lib/async/task.rb in async-1.20.0 vs lib/async/task.rb in async-1.20.1

- old
+ new

@@ -88,12 +88,15 @@ reactor.yield end # @attr fiber [Fiber] The fiber which is being used for the execution of this task. attr :fiber - def_delegators :@fiber, :alive? + def alive? + @fiber&.alive? + end + # @attr status [Symbol] The status of the execution of the fiber, one of `:initialized`, `:running`, `:complete`, `:stopped` or `:failed`. attr :status # Begin the execution of the task. def run(*args) @@ -140,11 +143,11 @@ elsif self.running? @status = :stopping if self.current? raise Stop, "Stopping current fiber!" - elsif @fiber.alive? + elsif @fiber&.alive? @fiber.resume(Stop.new) end end ensure @children&.each(&:stop) @@ -238,9 +241,12 @@ end end # Finish the current task, and all bound bound IO objects. def finish! + # Allow the fiber to be recycled. + @fiber = nil + # Attempt to remove this node from the task tree. consume # If this task was being used as a future, signal completion here: if @finished