module Is::Async
- public
-
Makes Ruby objects async-aware.
Constants
- VERSION
Public Class Methods
version()
click to toggle source
# File lib/is/async/version.rb, line 7 def self.version VERSION end
Public Instance Methods
async() { |task| ... }
click to toggle source
- public
-
Call asynchronous behavior in a proper async context.
# File lib/is/async.rb, line 15 def async ::Async::Reactor.run do |task| yield task end end
await() { |task| ... }
click to toggle source
- public
-
Call asynchronous behavior synchronously in a proper async context.
# File lib/is/async.rb, line 23 def await if (task = ::Async::Task.current?) yield task else ::Async::Reactor.run { |task| yield task }.wait end end
sleep(seconds)
click to toggle source
- public
-
Sleeps for `seconds` in a proper async context.
# File lib/is/async.rb, line 35 def sleep(seconds) await do |task| task.sleep(seconds) end end
timeout(seconds) { |task| ... }
click to toggle source
- public
-
Call asynchonous behavior in a proper async context, wrapped in a timeout.
Raises `Is::Async::Timeout` if execution exceeds `seconds`.
# File lib/is/async.rb, line 45 def timeout(seconds, &block) await do |task| if seconds && seconds > 0 task.with_timeout(seconds, Timeout) do yield task end else yield task end end end