Skip to content

Commit 45b991b

Browse files
committed
Make it possible to wrap/intercept task setup.
1 parent 5e5d84a commit 45b991b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/async/task.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ def run(*arguments)
117117
if @status == :initialized
118118
@status = :running
119119

120-
schedule(arguments)
120+
schedule do
121+
@block.call(self, *arguments)
122+
end
121123
else
122124
raise RuntimeError, "Task already running!"
123125
end
@@ -247,12 +249,12 @@ def stop!
247249
stop_children(true)
248250
end
249251

250-
def schedule(arguments)
252+
def schedule(&block)
251253
@fiber = Fiber.new do
252254
set!
253255

254256
begin
255-
@result = @block.call(self, *arguments)
257+
@result = yield
256258
@status = :complete
257259
# Console.logger.debug(self) {"Task was completed with #{@children.size} children!"}
258260
rescue Stop

0 commit comments

Comments
 (0)