Module: Puppeteer::ConcurrentRubyUtils
- Defined in:
- lib/puppeteer/concurrent_ruby_utils.rb
Overview
utility methods for Concurrent::Promises.
Instance Method Summary collapse
-
#await(future_or_value) ⇒ Object
blocking get value of Future.
-
#await_all(*args) ⇒ Object
wait for all promises.
-
#await_any(*args) ⇒ Object
wait for first promises.
- #future(&block) ⇒ Object
- #resolvable_future(&block) ⇒ Object
Instance Method Details
#await(future_or_value) ⇒ Object
blocking get value of Future.
26 27 28 29 30 31 32 |
# File 'lib/puppeteer/concurrent_ruby_utils.rb', line 26 def await(future_or_value) if future_or_value.is_a?(Concurrent::Promises::Future) future_or_value.value! else future_or_value end end |
#await_all(*args) ⇒ Object
wait for all promises. REMARK: This method doesn’t assure the order of calling. for example, await_all(async1, async2) calls calls2 -> calls1 often.
6 7 8 9 10 11 12 |
# File 'lib/puppeteer/concurrent_ruby_utils.rb', line 6 def await_all(*args) if args.length == 1 && args[0].is_a?(Enumerable) Concurrent::Promises.zip(*(args[0])).value! else Concurrent::Promises.zip(*args).value! end end |
#await_any(*args) ⇒ Object
wait for first promises. REMARK: This method doesn’t assure the order of calling. for example, await_all(async1, async2) calls calls2 -> calls1 often.
17 18 19 20 21 22 23 |
# File 'lib/puppeteer/concurrent_ruby_utils.rb', line 17 def await_any(*args) if args.length == 1 && args[0].is_a?(Enumerable) Concurrent::Promises.any(*(args[0])).value! else Concurrent::Promises.any(*args).value! end end |
#future(&block) ⇒ Object
34 35 36 |
# File 'lib/puppeteer/concurrent_ruby_utils.rb', line 34 def future(&block) Concurrent::Promises.future(&block) end |