Skip to content

Commit da9055f

Browse files
Fix state handling, possibly fixes #439.
1 parent b3561cc commit da9055f

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lib/async/task.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def self.run(scheduler, *arguments, **options, &block)
6161
# @parameter reactor [Reactor] the reactor this task will run within.
6262
# @parameter parent [Task] the parent task.
6363
def initialize(parent = Task.current?, finished: nil, **options, &block)
64-
super(parent, **options)
65-
6664
# These instance variables are critical to the state of the task.
6765
# In the initialized state, the @block should be set, but the @fiber should be nil.
6866
# In the running state, the @fiber should be set, and @block should be nil.
@@ -85,6 +83,9 @@ def initialize(parent = Task.current?, finished: nil, **options, &block)
8583
end
8684

8785
@defer_stop = nil
86+
87+
# Call this after all state is initialized, as it may call `add_child` which will set the parent and make it visible to the scheduler.
88+
super(parent, **options)
8889
end
8990

9091
# @returns [Scheduler] The scheduler for this task.

releases.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Improved handling of `Process.fork` on Ruby 4+.
6+
- Improve `@promise` state handling in `Task#initialize`, preventing incomplete instances being visible to the scheduler.
67

78
## v2.35.1
89

0 commit comments

Comments
 (0)