Class: Cocaine::Synchrony::Channel
- Defined in:
- lib/cocaine/synchrony/channel.rb
Instance Method Summary collapse
- #collect(count = 0) ⇒ Object
- #each ⇒ Object
-
#initialize(channel) ⇒ Channel
constructor
A new instance of Channel.
- #read ⇒ Object
Constructor Details
#initialize(channel) ⇒ Channel
Returns a new instance of Channel.
7 8 9 10 |
# File 'lib/cocaine/synchrony/channel.rb', line 7 def initialize(channel) @pending = [] register_fiber channel end |
Instance Method Details
#collect(count = 0) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/cocaine/synchrony/channel.rb', line 31 def collect(count=0) if count == 0 collect_until_choke else collect_until_count count end end |
#each ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/cocaine/synchrony/channel.rb', line 21 def each loop do begin yield Fiber.yield.get rescue ChokeEvent return end end end |
#read ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/cocaine/synchrony/channel.rb', line 12 def read if @pending.empty? future = Fiber.yield else future = @pending.pop end future.get end |