Class: Core::Async::Reactor
- Inherits:
-
Object
- Object
- Core::Async::Reactor
- Includes:
- Is::Async
- Defined in:
- lib/core/async/reactor.rb
Overview
- public
-
The top-level async context. Runs until all scheduled work is complete.
Class Method Summary collapse
-
.run(&block) ⇒ Object
- public
-
Create a new reactor and immediately run it.
Instance Method Summary collapse
-
#run ⇒ Object
- public
-
Run the reactor, yielding within the async context.
-
#stop ⇒ Object
- public
-
Stop the reactor.
Methods included from Is::Async
#async, #await, #aware, #defer, #resolve, #sleep, #timeout
Class Method Details
.run(&block) ⇒ Object
- public
-
Create a new reactor and immediately run it.
15 16 17 18 |
# File 'lib/core/async/reactor.rb', line 15 def run(&block) instance = new instance.run(&block) end |
Instance Method Details
#run ⇒ Object
- public
-
Run the reactor, yielding within the async context.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/core/async/reactor.rb', line 23 def run if (task = ::Async::Task.current?) reference = task.async { |child| @runnable = child yield self } wait_all(reference) else @runnable = ::Async::Reactor.new @runnable.run { async { yield self }.result }.wait end end |
#stop ⇒ Object
- public
-
Stop the reactor.
45 46 47 |
# File 'lib/core/async/reactor.rb', line 45 def stop @runnable&.stop end |