Class: Smirc::Queue
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#locked ⇒ Object
Returns the value of attribute locked.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#transferred ⇒ Object
Returns the value of attribute transferred.
Instance Method Summary collapse
- #<<(message) ⇒ Object
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #invoke ⇒ Object
- #limit_exceeded?(additional = 0) ⇒ Boolean
- #lock ⇒ Object
- #locked? ⇒ Boolean
- #send(message) ⇒ Object
- #should_invoke? ⇒ Boolean
- #size ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
6 7 8 9 10 11 |
# File 'lib/smirc/queue.rb', line 6 def initialize @locked = false @messages = [] @transferred = 0 @limit = 1400 end |
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit.
4 5 6 |
# File 'lib/smirc/queue.rb', line 4 def limit @limit end |
#locked ⇒ Object
Returns the value of attribute locked.
4 5 6 |
# File 'lib/smirc/queue.rb', line 4 def locked @locked end |
#messages ⇒ Object
Returns the value of attribute messages.
4 5 6 |
# File 'lib/smirc/queue.rb', line 4 def @messages end |
#transferred ⇒ Object
Returns the value of attribute transferred.
4 5 6 |
# File 'lib/smirc/queue.rb', line 4 def transferred @transferred end |
Instance Method Details
#<<(message) ⇒ Object
29 30 31 32 |
# File 'lib/smirc/queue.rb', line 29 def <<() @messages << invoke end |
#invoke ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/smirc/queue.rb', line 43 def invoke while(should_invoke?) do unless limit_exceeded?(.first.size) = .shift send() unless limit_exceeded? @transferred += .size lock if limit_exceeded? else lock end end end |
#limit_exceeded?(additional = 0) ⇒ Boolean
56 57 58 |
# File 'lib/smirc/queue.rb', line 56 def limit_exceeded?(additional = 0) @transferred + additional > @limit end |
#lock ⇒ Object
13 14 15 16 |
# File 'lib/smirc/queue.rb', line 13 def lock @locked = true fire(:lock) end |
#locked? ⇒ Boolean
25 26 27 |
# File 'lib/smirc/queue.rb', line 25 def locked? @locked end |
#send(message) ⇒ Object
60 61 62 |
# File 'lib/smirc/queue.rb', line 60 def send() fire(:send, ) end |
#should_invoke? ⇒ Boolean
38 39 40 |
# File 'lib/smirc/queue.rb', line 38 def should_invoke? !locked? && size > 0 end |
#size ⇒ Object
34 35 36 |
# File 'lib/smirc/queue.rb', line 34 def size @messages.size end |
#unlock ⇒ Object
18 19 20 21 22 23 |
# File 'lib/smirc/queue.rb', line 18 def unlock @locked = false @transferred = 0 fire(:unlock) invoke end |