lib/async/scheduler.rb in async-2.11.0 vs lib/async/scheduler.rb in async-2.12.0
- old
+ new
@@ -9,11 +9,10 @@
require_relative 'task'
require 'io/event'
require 'console'
-require 'timers'
require 'resolv'
module Async
# Handles scheduling of fibers. Implements the fiber scheduler interface.
class Scheduler < Node
@@ -38,11 +37,11 @@
@blocked = 0
@busy_time = 0.0
@idle_time = 0.0
- @timers = ::Timers::Group.new
+ @timers = ::IO::Event::Timers.new
end
# Compute the scheduler load according to the busy and idle times that are updated by the run loop.
# @returns [Float] The load of the scheduler. 0.0 means no load, 1.0 means fully loaded or over-loaded.
def load
@@ -163,11 +162,11 @@
@selector.transfer
ensure
@blocked -= 1
end
ensure
- timer&.cancel
+ timer&.cancel!
end
# @asynchronous May be called from any thread.
def unblock(blocker, fiber)
# $stderr.puts "unblock(#{blocker}, #{fiber})"
@@ -223,11 +222,11 @@
end
end
return @selector.io_wait(fiber, io, events)
ensure
- timer&.cancel
+ timer&.cancel!
end
if ::IO::Event::Support.buffer?
def io_read(io, buffer, length, offset = 0)
fiber = Fiber.current
@@ -238,11 +237,11 @@
end
end
@selector.io_read(fiber, io, buffer, length, offset)
ensure
- timer&.cancel
+ timer&.cancel!
end
if RUBY_ENGINE != "ruby" || RUBY_VERSION >= "3.3.1"
def io_write(io, buffer, length, offset = 0)
fiber = Fiber.current
@@ -253,11 +252,11 @@
end
end
@selector.io_write(fiber, io, buffer, length, offset)
ensure
- timer&.cancel
+ timer&.cancel!
end
end
end
# Wait for the specified process ID to exit.
@@ -414,10 +413,10 @@
end
end
yield timer
ensure
- timer.cancel if timer
+ timer&.cancel!
end
def timeout_after(duration, exception, message, &block)
with_timeout(duration, exception, message) do |timer|
yield duration