lib/async/task.rb in async-2.15.1 vs lib/async/task.rb in async-2.15.2
- old
+ new
@@ -251,22 +251,22 @@
if self.stopped?
# If the task is already stopped, a `stop` state transition re-enters the same state which is a no-op. However, we will also attempt to stop any running children too. This can happen if the children did not stop correctly the first time around. Doing this should probably be considered a bug, but it's better to be safe than sorry.
return stopped!
end
- # If we are deferring stop...
- if @defer_stop == false
- # Don't stop now... but update the state so we know we need to stop later.
- @defer_stop = true
- return false
- end
-
# If the fiber is alive, we need to stop it:
if @fiber&.alive?
# As the task is now exiting, we want to ensure the event loop continues to execute until the task finishes.
self.transient = false
+ # If we are deferring stop...
+ if @defer_stop == false
+ # Don't stop now... but update the state so we know we need to stop later.
+ @defer_stop = true
+ return false
+ end
+
if self.current?
# If the fiber is current, and later is `true`, we need to schedule the fiber to be stopped later, as it's currently invoking `stop`:
if later
# If the fiber is the current fiber and we want to stop it later, schedule it:
Fiber.scheduler.push(Stop::Later.new(self))
@@ -322,9 +322,14 @@
end
else
# If we are deferring stop already, entering it again is a no-op.
yield
end
+ end
+
+ # @returns [Boolean] Whether stop has been deferred.
+ def stop_deferred?
+ @defer_stop
end
# Lookup the {Task} for the current fiber. Raise `RuntimeError` if none is available.
# @returns [Task]
# @raises[RuntimeError] If task was not {set!} for the current fiber.