lib/async/task.rb in async-0.16.0 vs lib/async/task.rb in async-0.17.0

- old
+ new

@@ -24,11 +24,11 @@ require_relative 'node' require_relative 'condition' module Async # Raised when a task is explicitly stopped. - class Interrupt < Exception + class Stop < Exception end # A task represents the state associated with the execution of an asynchronous # block. class Task < Node @@ -72,13 +72,13 @@ begin @result = yield(self, *args) @status = :complete # Async.logger.debug("Task #{self} completed normally.") - rescue Interrupt - @status = :interrupted - # Async.logger.debug("Task #{self} interrupted: #{$!}") + rescue Stop + @status = :stop + # Async.logger.debug("Task #{self} stopped: #{$!}") rescue Exception => error @result = error @status = :failed # Async.logger.debug("Task #{self} failed: #{$!}") raise @@ -99,11 +99,11 @@ # @attr fiber [Fiber] The fiber which is being used for the execution of this task. attr :fiber def_delegators :@fiber, :alive? - # @attr status [Symbol] The status of the execution of the fiber, one of `:running`, `:complete`, `:interrupted`, or `:failed`. + # @attr status [Symbol] The status of the execution of the fiber, one of `:running`, `:complete`, `:stopped`, or `:failed`. attr :status # Resume the execution of the task. def run(*args) if @status == :initialized @@ -142,11 +142,10 @@ # @return [void] def stop @children.each(&:stop) if @fiber.alive? - exception = Interrupt.new("Stop right now!") - @fiber.resume(exception) + @fiber.resume(Stop.new) end end # Lookup the {Task} for the current fiber. Raise `RuntimeError` if none is available. # @return [Async::Task]