Sha256: 8604a4d5e412e76a858ad15cdb8cfe6a3dedc562fd8ebf952175bccd22bf1f84
Contents?: true
Size: 1.02 KB
Versions: 16
Compression:
Stored size: 1.02 KB
Contents
module Puppeteer::DefineAsyncMethod refine Class do def define_async_method(async_method_name) unless async_method_name.to_s.start_with?('async_') raise ArgumentError.new('async method name should start with "async_"') end if method_defined?(async_method_name) || private_method_defined?(async_method_name) raise ArgumentError.new("#{async_method_name} is already defined") end original_method = instance_method(async_method_name[6..-1]) define_method(async_method_name) do |*args, **kwargs| if kwargs.empty? # for Ruby < 2.7 Concurrent::Promises.future do original_method.bind(self).call(*args) rescue => err Logger.new($stderr).warn(err) raise err end else Concurrent::Promises.future do original_method.bind(self).call(*args, **kwargs) rescue => err Logger.new($stderr).warn(err) raise err end end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems