lib/async/task.rb in async-2.15.2 vs lib/async/task.rb in async-2.15.3
- old
+ new
@@ -302,22 +302,26 @@
# Tri-state variable for controlling stop:
# - nil: defer_stop has not been called.
# - false: defer_stop has been called and we are not stopping.
# - true: defer_stop has been called and we will stop when exiting the block.
if @defer_stop.nil?
- # If we are not deferring stop already, we can defer it now:
- @defer_stop = false
-
begin
+ # If we are not deferring stop already, we can defer it now:
+ @defer_stop = false
+
yield
rescue Stop
# If we are exiting due to a stop, we shouldn't try to invoke stop again:
@defer_stop = nil
raise
ensure
+ defer_stop = @defer_stop
+
+ # We need to ensure the state is reset before we exit the block:
+ @defer_stop = nil
+
# If we were asked to stop, we should do so now:
- if @defer_stop
- @defer_stop = nil
+ if defer_stop
raise Stop, "Stopping current task (was deferred)!"
end
end
else
# If we are deferring stop already, entering it again is a no-op.