From 45b991b22125c50de2b77f2fb76e77e041b3ca2b Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 5 Sep 2022 16:35:38 +1200 Subject: [PATCH] Make it possible to wrap/intercept task setup. --- lib/async/task.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/async/task.rb b/lib/async/task.rb index e4de5261..2a8495dd 100644 --- a/lib/async/task.rb +++ b/lib/async/task.rb @@ -117,7 +117,9 @@ def run(*arguments) if @status == :initialized @status = :running - schedule(arguments) + schedule do + @block.call(self, *arguments) + end else raise RuntimeError, "Task already running!" end @@ -247,12 +249,12 @@ def stop! stop_children(true) end - def schedule(arguments) + def schedule(&block) @fiber = Fiber.new do set! begin - @result = @block.call(self, *arguments) + @result = yield @status = :complete # Console.logger.debug(self) {"Task was completed with #{@children.size} children!"} rescue Stop