Class: Playwright::WaitHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/playwright/wait_helper.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWaitHelper

Returns a new instance of WaitHelper.



5
6
7
8
# File 'lib/playwright/wait_helper.rb', line 5

def initialize
  @promise = Concurrent::Promises.resolvable_future
  @registered_listeners = Set.new
end

Instance Attribute Details

#promiseObject (readonly)

Returns the value of attribute promise.



50
51
52
# File 'lib/playwright/wait_helper.rb', line 50

def promise
  @promise
end

Instance Method Details

#reject_on_event(emitter, event, error, predicate: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/playwright/wait_helper.rb', line 10

def reject_on_event(emitter, event, error, predicate: nil)
  listener = -> (*args) {
    if !predicate || predicate.call(*args)
      reject(error)
    end
  }
  emitter.on(event, listener)
  @registered_listeners << [emitter, event, listener]

  self
end

#reject_on_timeout(timeout_ms, message) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/playwright/wait_helper.rb', line 22

def reject_on_timeout(timeout_ms, message)
  return if timeout_ms <= 0

  Concurrent::Promises.schedule(timeout_ms / 1000.0) {
    reject(TimeoutError.new(message: message))
  }

  self
end

#wait_for_event(emitter, event, predicate: nil) ⇒ Object

Parameters:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/playwright/wait_helper.rb', line 34

def wait_for_event(emitter, event, predicate: nil)
  listener = -> (*args) {
    begin
      if !predicate || predicate.call(*args)
        fulfill(*args)
      end
    rescue => err
      reject(err)
    end
  }
  emitter.on(event, listener)
  @registered_listeners << [emitter, event, listener]

  self
end