lib/async/task.rb in async-1.18.0 vs lib/async/task.rb in async-1.19.0

- old
+ new

@@ -134,11 +134,13 @@ # Stop the task and all of its children. # @return [void] def stop @children&.each(&:stop) - if @fiber.alive? + if self.current? + raise Stop, "Stopping current fiber!" + elsif @fiber.alive? @fiber.resume(Stop.new) end end # Lookup the {Task} for the current fiber. Raise `RuntimeError` if none is available. @@ -150,9 +152,13 @@ # Check if there is a task defined for the current fiber. # @return [Async::Task, nil] def self.current? Thread.current[:async_task] + end + + def current? + self.equal?(Thread.current[:async_task]) end # Check if the task is running. # @return [Boolean] def running?