File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change 1313require_relative 'node'
1414require_relative 'condition'
1515
16+ Fiber . attr_accessor :async_task
17+
1618module Async
1719 # Raised when a task is explicitly stopped.
1820 class Stop < Exception
@@ -325,13 +327,13 @@ def defer_stop
325327 # @returns [Task]
326328 # @raises[RuntimeError] If task was not {set!} for the current fiber.
327329 def self . current
328- Thread . current [ : async_task] or raise RuntimeError , "No async task available!"
330+ Fiber . current . async_task or raise RuntimeError , "No async task available!"
329331 end
330332
331333 # Check if there is a task defined for the current fiber.
332334 # @returns [Interface(:async) | Nil]
333335 def self . current?
334- Thread . current [ : async_task]
336+ Fiber . current . async_task
335337 end
336338
337339 # @returns [Boolean] Whether this task is the currently executing task.
@@ -397,8 +399,6 @@ def stop!
397399
398400 def schedule ( &block )
399401 @fiber = Fiber . new ( annotation : self . annotation ) do
400- set!
401-
402402 begin
403403 completed! ( yield )
404404 rescue Stop
@@ -416,13 +416,9 @@ def schedule(&block)
416416 end
417417 end
418418
419+ @fiber . async_task = self
420+
419421 self . root . resume ( @fiber )
420422 end
421-
422- # Set the current fiber's `:async_task` to this task.
423- def set!
424- # This is actually fiber-local:
425- Thread . current [ :async_task ] = self
426- end
427423 end
428424end
You can’t perform that action at this time.
0 commit comments