Skip to content

Commit f575160

Browse files
committed
Add support for IO::Event::Profiler.
1 parent 9ee239b commit f575160

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Diff for: async.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
2727

2828
spec.add_dependency "console", "~> 1.29"
2929
spec.add_dependency "fiber-annotation"
30-
spec.add_dependency "io-event", "~> 1.7"
30+
spec.add_dependency "io-event", "~> 1.9"
3131
spec.add_dependency "traces", "~> 0.15"
3232
spec.add_dependency "metrics", "~> 0.12"
3333
end

Diff for: lib/async/scheduler.rb

+15-7
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ def self.supported?
4242
# @public Since *Async v1*.
4343
# @parameter parent [Node | Nil] The parent node to use for task hierarchy.
4444
# @parameter selector [IO::Event::Selector] The selector to use for event handling.
45-
def initialize(parent = nil, selector: nil, worker_pool: DEFAULT_WORKER_POOL)
45+
def initialize(parent = nil, selector: nil, profiler: IO::Event::Profiler.default, worker_pool: DEFAULT_WORKER_POOL)
4646
super(parent)
4747

4848
@selector = selector || ::IO::Event::Selector.new(Fiber.current)
49+
@profiler = profiler
50+
4951
@interrupted = false
5052

5153
@blocked = 0
@@ -492,13 +494,19 @@ def stop
492494
def run(...)
493495
Kernel.raise ClosedError if @selector.nil?
494496

495-
initial_task = self.async(...) if block_given?
496-
497-
self.run_loop do
498-
run_once
497+
begin
498+
@profiler&.start
499+
500+
initial_task = self.async(...) if block_given?
501+
502+
self.run_loop do
503+
run_once
504+
end
505+
506+
return initial_task
507+
ensure
508+
@profiler&.stop
499509
end
500-
501-
return initial_task
502510
end
503511

504512
# Start an asynchronous task within the specified reactor. The task will be executed until the first blocking call, at which point it will yield and and this method will return.

Diff for: test/io.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@
4545
it "can write with timeout" do
4646
skip_unless_constant_defined(:TimeoutError, IO)
4747

48+
big = "x" * 1024 * 1024
49+
4850
input, output = IO.pipe
4951
output.timeout = 0.001
5052

5153
expect do
5254
while true
53-
output.write("Hello")
55+
output.write(big)
5456
end
5557
end.to raise_exception(::IO::TimeoutError)
5658
end

0 commit comments

Comments
 (0)