Class: CSP::Channel
Instance Method Summary collapse
- #<<(message) ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ Channel
constructor
A new instance of Channel.
- #read(options = {}) ⇒ Object
- #write(message) ⇒ Object
Constructor Details
#initialize ⇒ Channel
Returns a new instance of Channel.
8 9 10 11 |
# File 'lib/csp/channel.rb', line 8 def initialize @readers = [] @writers = [] end |
Instance Method Details
#<<(message) ⇒ Object
49 50 51 52 |
# File 'lib/csp/channel.rb', line 49 def << write() return self end |
#each ⇒ Object
54 55 56 |
# File 'lib/csp/channel.rb', line 54 def each yield read while true end |
#read(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/csp/channel.rb', line 13 def read( = {}) = callcc do |cont| @readers << cont if @writers.empty? if [:callback] return else CSP.run end else @writers.shift.call end end if [:callback] [:callback].call() else return end end |