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