Sha256: 23893771a98b9e6551c2e72eb34ab8c5089dc1f0a814c031635d503a2dfe8ec4

Contents?: true

Size: 752 Bytes

Versions: 7

Compression:

Stored size: 752 Bytes

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|
        Concurrent::Promises.future do
          original_method.bind(self).call(*args)
        rescue => err
          Logger.new($stderr).warn(err)
          raise err
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
puppeteer-ruby-0.0.26 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.25 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.23 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.22 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.21 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.20 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.19 lib/puppeteer/define_async_method.rb