Module: Puppeteer::ConcurrentRubyUtils

Defined in:
lib/puppeteer/concurrent_ruby_utils.rb

Overview

utility methods for Concurrent::Promises.

Instance Method Summary collapse

Instance Method Details

#await(future_or_value) ⇒ Object

blocking get value of Future.



20
21
22
23
24
25
26
# File 'lib/puppeteer/concurrent_ruby_utils.rb', line 20

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



3
4
5
6
7
8
9
# File 'lib/puppeteer/concurrent_ruby_utils.rb', line 3

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



11
12
13
14
15
16
17
# File 'lib/puppeteer/concurrent_ruby_utils.rb', line 11

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



28
29
30
# File 'lib/puppeteer/concurrent_ruby_utils.rb', line 28

def future(&block)
  Concurrent::Promises.future(&block)
end

#resolvable_futureObject



32
33
34
# File 'lib/puppeteer/concurrent_ruby_utils.rb', line 32

def resolvable_future
  Concurrent::Promises.resolvable_future
end