Class: Async2
- Inherits:
-
Object
- Object
- Async2
- Includes:
- HTTP, Singleton
- Defined in:
- lib/async2.rb,
lib/async2/http.rb,
lib/async2/version.rb
Defined Under Namespace
Modules: HTTP
Constant Summary collapse
- VERSION =
"0.1.0"
Constants included from HTTP
Instance Attribute Summary collapse
-
#wait ⇒ Object
Returns the value of attribute wait.
Instance Method Summary collapse
-
#initialize(wait = 0.01) ⇒ Async2
constructor
A new instance of Async2.
- #read(io, &b) ⇒ Object
- #write(io, &b) ⇒ Object
Methods included from HTTP
Constructor Details
#initialize(wait = 0.01) ⇒ Async2
Returns a new instance of Async2.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Attribute Details
#wait ⇒ Object
Returns the value of attribute wait.
6 7 8 |
# File 'lib/async2.rb', line 6 def wait @wait end |
Instance Method Details
#read(io, &b) ⇒ Object
28 29 30 |
# File 'lib/async2.rb', line 28 def read(io, &b) @read[io] = b end |
#write(io, &b) ⇒ Object
32 33 34 |
# File 'lib/async2.rb', line 32 def write(io, &b) @write[io] = b end |