8000 Don't allow creation of a task on a finished parent. · socketry/async@ecb7820 · GitHub
[go: up one dir, main page]

Skip to content

Commit ecb7820

Browse files
committed
Don't allow creation of a task on a finished parent.
1 parent c84f883 commit ecb7820

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/async/task.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def run(*arguments)
113113

114114
# Run an asynchronous task as a child of the current task.
115115
def async(*arguments, **options, &block)
116+
raise "Cannot create child task within a task that has finished execution!" if self.finished?
117+
116118
task = Task.new(self, **options, &block)
117119

118120
task.run(*arguments)

test/async/task.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
describe Async::Task do
1313
let(:reactor) {Async::Reactor.new}
1414

15-
describe '.yield' do
15+
with '.yield' do
1616
it "can yield back to scheduler" do
1717
state = nil
1818

@@ -142,6 +142,18 @@
142142
end
143143
end.to raise_exception(SignalException, message: be =~ /TERM/)
144144
end
145+
146+
it "can't start child task after finishing" do
147+
task = reactor.async do |task|
148+
end
149+
150+
task.wait
151+
152+
expect do
153+
task.async do |task|
154+
end
155+
end.to raise_exception(RuntimeError, message: be =~ /finished/)
156+
end
145157
end
146158

147159
with '#yield' do

0 commit comments

Comments
 (0)
0