lib/async/task.rb in async-1.22.2 vs lib/async/task.rb in async-1.23.0
- old
+ new
@@ -83,11 +83,11 @@
@fiber = make_fiber(&block)
end
def to_s
- "<#{self.description} #{@status}>"
+ "\#<#{self.description} (#{@status})>"
end
def logger
@logger ||= @parent&.logger
end
@@ -147,19 +147,23 @@
alias result wait
# Soon to become attr :result
# Stop the task and all of its children.
# @return [void]
- def stop
+ def stop(later = false)
if self.stopped?
# If we already stopped this task... don't try to stop it again:
return
end
if self.running?
if self.current?
- raise Stop, "Stopping current fiber!"
+ if later
+ @reactor << Stop::Later.new(self)
+ else
+ raise Stop, "Stopping current task!"
+ end
elsif @fiber&.alive?
begin
@fiber.resume(Stop.new)
rescue FiberError
@reactor << Stop::Later.new(self)
@@ -233,12 +237,15 @@
logger.debug(self) {$!}
end
end
def stop!
- # logger.debug(self) {"Task was stopped with #{@children.size} children!"}
+ # logger.debug(self) {"Task was stopped with #{@children&.size.inspect} children!"}
@status = :stopped
- @children&.each(&:stop)
+
+ @children&.each do |child|
+ child.stop(true)
+ end
end
def make_fiber(&block)
Fiber.new do |*args|
set!