Skip to content

Commit

Permalink
ref: Always put target to targets
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Jan 5, 2024
1 parent 5cb2512 commit 1c429dc
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 28 deletions.
2 changes: 2 additions & 0 deletions lib/ferrum.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "concurrent-ruby"
require "ferrum/utils/event"
require "ferrum/utils/thread"
require "ferrum/utils/platform"
require "ferrum/utils/elapsed_time"
Expand Down
9 changes: 3 additions & 6 deletions lib/ferrum/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,14 @@ def create_target
target = @pendings.take(@client.timeout)
raise NoSuchTargetError unless target.is_a?(Target)

@targets.put_if_absent(target.id, target)
target
end

def add_target(params)
target = Target.new(@client, params)
if target.window?
@targets.put_if_absent(target.id, target)
else
@pendings.put(target, @client.timeout)
end
@targets.put_if_absent(target.id, target)

@pendings.put(target, @client.timeout) if @pendings.empty?
end

def update_target(target_id, params)
Expand Down
2 changes: 1 addition & 1 deletion lib/ferrum/downloads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Downloads

def initialize(page)
@page = page
@event = Event.new.tap(&:set)
@event = Utils::Event.new.tap(&:set)
@files = {}
end

Expand Down
17 changes: 0 additions & 17 deletions lib/ferrum/event.rb

This file was deleted.

3 changes: 1 addition & 2 deletions lib/ferrum/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "forwardable"
require "pathname"
require "ferrum/event"
require "ferrum/mouse"
require "ferrum/keyboard"
require "ferrum/headers"
Expand Down Expand Up @@ -73,7 +72,7 @@ def initialize(client, context_id:, target_id:, proxy: nil)

@frames = Concurrent::Map.new
@main_frame = Frame.new(nil, self)
@event = Event.new.tap(&:set)
@event = Utils::Event.new.tap(&:set)
self.proxy = proxy

@mouse = Mouse.new(self)
Expand Down
2 changes: 0 additions & 2 deletions lib/ferrum/utils/elapsed_time.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "concurrent-ruby"

module Ferrum
module Utils
module ElapsedTime
Expand Down
19 changes: 19 additions & 0 deletions lib/ferrum/utils/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Ferrum
module Utils
class Event < Concurrent::Event
def iteration
synchronize { @iteration }
end

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

0 comments on commit 1c429dc

Please sign in to comment.