Skip to content

Commit 4d09160

Browse files
Add support for IO::Event::WorkerPool.
1 parent f30c2f8 commit 4d09160

File tree

4 files changed

+25
-247
lines changed

4 files changed

+25
-247
lines changed

gems.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
gemspec
1111

12-
# gem "io-event", git: "https://github.com/socketry/io-event.git"
12+
gem "io-event", git: "https://github.com/samuel-williams-shopify/io-event.git", branch: "native-work-pool"
1313

1414
# In order to capture both code paths in coverage, we need to optionally load this gem:
1515
if ENV["FIBER_PROFILER_CAPTURE"] == "true"

lib/async/scheduler.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
require_relative "clock"
99
require_relative "task"
1010
require_relative "timeout"
11-
require_relative "worker_pool"
1211

1312
require "io/event"
1413

@@ -45,6 +44,22 @@ def initialize(message = "Scheduler is closed!")
4544
def self.supported?
4645
true
4746
end
47+
48+
# Used to augment the scheduler to add support for blocking operations.
49+
module BlockingOperationWait
50+
# Wait for the given work to be executed.
51+
#
52+
# @public Since *Async v2.21* and *Ruby v3.4*.
53+
# @asynchronous May be non-blocking.
54+
#
55+
# @parameter work [Proc] The work to execute on a background thread.
56+
# @returns [Object] The result of the work.
57+
def blocking_operation_wait(work)
58+
@worker_pool.call(work)
59+
end
60+
end
61+
62+
private_constant :BlockingOperationWait
4863

4964
# Create a new scheduler.
5065
#
@@ -65,14 +80,19 @@ def initialize(parent = nil, selector: nil, profiler: Profiler&.default, worker_
6580
@idle_time = 0.0
6681

6782
@timers = ::IO::Event::Timers.new
83+
6884
if worker_pool == true
69-
@worker_pool = WorkerPool.new
85+
if ::IO::Event.const_defined?(:WorkerPool)
86+
@worker_pool = ::IO::Event::WorkerPool.new
87+
else
88+
@worker_pool = nil
89+
end
7090
else
7191
@worker_pool = worker_pool
7292
end
73-
93+
7494
if @worker_pool
75-
self.singleton_class.prepend(WorkerPool::BlockingOperationWait)
95+
self.singleton_class.prepend(BlockingOperationWait)
7696
end
7797
end
7898

lib/async/worker_pool.rb

Lines changed: 0 additions & 182 deletions
This file was deleted.

test/async/worker_pool.rb

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)