class Async2
Constants
- VERSION
Attributes
wait[RW]
Public Class Methods
new(wait = 0.01)
click to toggle source
# File lib/async2.rb, line 8 def initialize wait = 0.01 @wait = wait @read = {} @write = {} @t = Thread.new do loop do begin read, write = IO.select @read.keys, @write.keys, nil, 0 read&.each { |io| @read[io].call(io); @read.delete io } write&.each { |io| @write[io].call(io); @write.delete io } sleep wait unless read || write rescue => err STDERR.puts err, err.backtrace raise retry end end end end
Public Instance Methods
read(io, &b)
click to toggle source
# File lib/async2.rb, line 28 def read(io, &b) @read[io] = b end
write(io, &b)
click to toggle source
# File lib/async2.rb, line 32 def write(io, &b) @write[io] = b end