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

Version Path
puppeteer-ruby-0.33.0 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.32.4 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.32.3 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.32.2 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.32.1 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.32.0 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.31.6 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.31.5 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.31.4 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.31.3 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.31.1 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.31.0 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.30.0 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.29.0 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.28.1 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.27 lib/puppeteer/define_async_method.rb