Class: Capybara::Lightpanda::Utils::Event

Inherits:
Concurrent::Event
  • Object
show all
Defined in:
lib/capybara/lightpanda/utils/event.rb

Overview

Concurrent::Event with an iteration counter so callers can detect that the event was reset (e.g. a new navigation started) while they were waiting on it. Mirrors ferrum’s Utils::Event.

The base Concurrent::Event allows wait/set/reset cycles, but a wait that returns true after a reset → set is indistinguishable from one that returned true on the original set. The iteration counter, bumped on every reset, lets callers compare before and after to tell whether the event was raced by a reset.

Instance Method Summary collapse

Constructor Details

#initializeEvent

Returns a new instance of Event.



18
19
20
21
# File 'lib/capybara/lightpanda/utils/event.rb', line 18

def initialize
  super
  @iteration = 0
end

Instance Method Details

#iterationObject



23
24
25
# File 'lib/capybara/lightpanda/utils/event.rb', line 23

def iteration
  synchronize { @iteration }
end

#resetObject



27
28
29
30
31
32
33
# File 'lib/capybara/lightpanda/utils/event.rb', line 27

def reset
  synchronize do
    @iteration += 1
    @set = false if @set
    @iteration
  end
end