Module: Bacon::AsyncSpec
- Defined in:
- lib/bacon/ext/async.rb
Class Attribute Summary collapse
-
.top_task ⇒ Object
Returns the value of attribute top_task.
Instance Method Summary collapse
- #cancel_timer ⇒ Object
- #done ⇒ Object
-
#run ⇒ Object
def run_requirement(title, *args) p [:RUN_START, title] super(title, *args) p [:RUN_END] end.
- #wait(timeout = 0.1) ⇒ Object
- #wakeup ⇒ Object
Class Attribute Details
.top_task ⇒ Object
Returns the value of attribute top_task.
8 9 10 |
# File 'lib/bacon/ext/async.rb', line 8 def top_task @top_task end |
Instance Method Details
#cancel_timer ⇒ Object
23 24 25 26 27 28 |
# File 'lib/bacon/ext/async.rb', line 23 def cancel_timer() if @timeout_timer @timeout_timer.cancel() @timeout_timer = nil end end |
#done ⇒ Object
47 48 49 |
# File 'lib/bacon/ext/async.rb', line 47 def done wakeup() end |
#run ⇒ Object
def run_requirement(title, *args)
p [:RUN_START, title]
super(title, *args)
p [:RUN_END]
end
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bacon/ext/async.rb', line 57 def run(*) if AsyncSpec.top_task && (AsyncSpec.top_task == Async::Task.current?) super else Async::Reactor.run do |task| task.async do |reactor| AsyncSpec.top_task = Async::Task.current? begin super reactor.stop() ensure AsyncSpec.top_task = nil end end end end end |
#wait(timeout = 0.1) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bacon/ext/async.rb', line 30 def wait(timeout = 0.1) cancel_timer() @waiting_task = Async::Task.current @timeout_timer = @waiting_task.reactor.after(timeout) do wakeup() end Async::Task.yield() # Fiber.yield() ensure cancel_timer() @waiting_task = nil end |
#wakeup ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bacon/ext/async.rb', line 11 def wakeup if @waiting_task t = @waiting_task @waiting_task.reactor.after(0) do t.fiber.resume() end @waiting_task = nil end end |