Class: Playwright::Connection
- Inherits:
-
Object
- Object
- Playwright::Connection
- Defined in:
- lib/playwright/connection.rb
Overview
Instance Method Summary collapse
- #async_send_message_to_server(guid, method, params) ⇒ Object
- #async_wait_for_object_with_known_name(guid) ⇒ Object
-
#initialize(playwright_cli_executable_path:) ⇒ Connection
constructor
A new instance of Connection.
- #run ⇒ Object
- #send_message_to_server(guid, method, params) ⇒ Object
- #stop ⇒ Object
- #wait_for_object_with_known_name(guid) ⇒ Object
Constructor Details
#initialize(playwright_cli_executable_path:) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/playwright/connection.rb', line 8 def initialize(playwright_cli_executable_path:) @transport = Transport.new( playwright_cli_executable_path: playwright_cli_executable_path ) @transport. do || dispatch() end @objects = {} # Hash[ guid => ChannelOwner ] @waiting_for_object = {} # Hash[ guid => Promise<ChannelOwner> ] @callbacks = {} # Hash [ guid => Promise<ChannelOwner> ] @root_object = RootChannelOwner.new(self) end |
Instance Method Details
#async_send_message_to_server(guid, method, params) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/playwright/connection.rb', line 44 def (guid, method, params) callback = Concurrent::Promises.resolvable_future with_generated_id do |id| # register callback promise object first. # @see https://github.com/YusukeIwaki/puppeteer-ruby/pull/34 @callbacks[id] = callback = { id: id, guid: guid, method: method, params: replace_channels_with_guids(params), } begin @transport.() rescue => err @callbacks.delete(id) callback.reject(err) raise unless err.is_a?(Transport::AlreadyDisconnectedError) end end callback end |
#async_wait_for_object_with_known_name(guid) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/playwright/connection.rb', line 30 def async_wait_for_object_with_known_name(guid) if @objects[guid] return @objects[guid] end callback = Concurrent::Promises.resolvable_future @waiting_for_object[guid] = callback callback end |
#run ⇒ Object
22 23 24 |
# File 'lib/playwright/connection.rb', line 22 def run @transport.run end |
#send_message_to_server(guid, method, params) ⇒ Object
70 71 72 |
# File 'lib/playwright/connection.rb', line 70 def (guid, method, params) (guid, method, params).value! end |
#stop ⇒ Object
26 27 28 |
# File 'lib/playwright/connection.rb', line 26 def stop @transport.stop end |
#wait_for_object_with_known_name(guid) ⇒ Object
40 41 42 |
# File 'lib/playwright/connection.rb', line 40 def wait_for_object_with_known_name(guid) async_wait_for_object_with_known_name.value! end |