lib/rainbows/thread_timeout.rb in rainbows-4.7.0 vs lib/rainbows/thread_timeout.rb in rainbows-5.0.0
- old
+ new
@@ -61,11 +61,11 @@
# in app-level code. timeout.rb does something similar
ExecutionExpired = Class.new(Exception)
# The MRI 1.8 won't be usable in January 2038, we'll raise this
# when we eventually drop support for 1.8 (before 2038, hopefully)
- NEVER = Time.at(0x7fffffff)
+ NEVER = 0x7fffffff
def initialize(app, opts)
# @timeout must be Numeric since we add this to Time
@timeout = opts[:timeout]
Numeric === @timeout or
@@ -112,11 +112,11 @@
# we're dead if anything in the next two lines raises, but it's
# highly unlikely that they will, and anything such as NoMemoryError
# is hopeless and we might as well just die anyways.
# initialize guarantees @timeout will be Numeric
start_watchdog(env) unless @watchdog
- @active[Thread.current] = Time.now + @timeout
+ @active[Thread.current] = Rainbows.now + @timeout
begin
# It is important to unlock inside this begin block
# Mutex#unlock really can't fail here since we did a successful
# Mutex#lock before
@@ -160,11 +160,11 @@
# We always lock access to @active, so we can't kill threads
# that are about to release themselves from the eye of the
# watchdog thread.
@lock.synchronize do
- now = Time.now
+ now = Rainbows.now
@active.delete_if do |thread, expire_at|
# We also use this loop to get the maximum possible time to
# sleep for if we're not killing the thread.
if expire_at > now
next_expiry = expire_at if next_expiry > expire_at
@@ -182,10 +182,10 @@
# value.
if next_expiry == NEVER
sleep(@timeout)
else
# sleep until the next known thread is about to expire.
- sec = next_expiry - Time.now
+ sec = next_expiry - Rainbows.now
sec > 0.0 ? sleep(sec) : Thread.pass # give other threads a chance
end
rescue => e
# just in case
logger.error e