Sha256: 57064dd57d5cde7251c19fa59c0a72216bc8e83c8f7a0e81dfc478898c8571cb

Contents?: true

Size: 751 Bytes

Versions: 5

Compression:

Stored size: 751 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

5 entries across 5 versions & 1 rubygems

Version Path
puppeteer-ruby-0.0.18 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.17 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.16 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.15 lib/puppeteer/define_async_method.rb
puppeteer-ruby-0.0.14 lib/puppeteer/define_async_method.rb