lib/puppeteer/concurrent_ruby_utils.rb in puppeteer-ruby-0.33.0 vs lib/puppeteer/concurrent_ruby_utils.rb in puppeteer-ruby-0.34.0

- old
+ new

@@ -1,7 +1,25 @@ # utility methods for Concurrent::Promises. module Puppeteer::ConcurrentRubyUtils + module ConcurrentPromisesFutureExtension + # Extension for describing 2 concurrent tasks smartly. + # + # page.async_for_navigation.with_waiting_for_complete do + # page.click('#submit') + # end + def with_waiting_for_complete(&block) + async_block_call = Concurrent::Promises.future do + block.call + rescue => err + Logger.new($stderr).warn(err) + raise err + end + + Concurrent::Promises.zip(self, async_block_call).value!.first + end + end + # wait for all promises. # REMARK: This method doesn't assure the order of calling. # for example, await_all(async1, async2) calls calls2 -> calls1 often. def await_all(*args) if args.length == 1 && args.first.is_a?(Enumerable) @@ -46,18 +64,18 @@ # suppress error logging raise rescue => err Logger.new($stderr).warn(err) raise err - end + end.extend(ConcurrentPromisesFutureExtension) end def resolvable_future(&block) future = Concurrent::Promises.resolvable_future if block block.call(future) end - future + future.extend(ConcurrentPromisesFutureExtension) end end include Puppeteer::ConcurrentRubyUtils