lib/async/scheduler.rb in async-2.8.1 vs lib/async/scheduler.rb in async-2.8.2
- old
+ new
@@ -47,10 +47,17 @@
end
ensure
self.close
end
+ # Terminate the scheduler. We deliberately ignore interrupts here, as this code can be called from an interrupt, and we don't want to be interrupted while cleaning up.
+ def terminate
+ Thread.handle_interrupt(::Interrupt => :never) do
+ super
+ end
+ end
+
# @public Since `stable-v1`.
def close
# It's critical to stop all tasks. Otherwise they might be holding on to resources which are never closed/released correctly.
until self.terminate
self.run_once!
@@ -306,20 +313,23 @@
initial_task = self.async(...) if block_given?
begin
# In theory, we could use Exception here to be a little bit safer, but we've only shown the case for SignalException to be a problem, so let's not over-engineer this.
- Thread.handle_interrupt(SignalException => :never) do
+ Thread.handle_interrupt(::SignalException => :never) do
while true
# If we are interrupted, we need to exit:
break if self.interrupted?
# If we are finished, we need to exit:
break unless self.run_once
end
end
rescue Interrupt
- self.stop
+ Thread.handle_interrupt(::SignalException => :never) do
+ self.stop
+ end
+
retry
end
return initial_task
ensure