Skip to content

Commit 15b87ce

Browse files
committed
fix: register a promise as waiting_work only if it is being executed
1 parent 609293f commit 15b87ce

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

lib/roby/promise.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def initialize(
3939
executor: execution_engine.thread_pool, description: "promise", &block
4040
)
4141
@execution_engine = execution_engine
42-
execution_engine.waiting_work << self
4342
@description = description
4443

4544
@pipeline = []
@@ -260,6 +259,7 @@ def fail(exception = StandardError)
260259
end
261260

262261
def execute
262+
execution_engine.waiting_work << self
263263
promise.execute
264264
self
265265
end

test/test_execution_engine.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,13 @@ module Roby
9999
end
100100

101101
describe "promise handling" do
102-
it "queues promises in the #waiting_work list" do
102+
it "does not queue a promise in #waiting_work on creation" do
103103
p = execution_engine.promise {}
104+
refute execution_engine.waiting_work.include?(p)
105+
end
106+
107+
it "queues a promise in #waiting_work on execution" do
108+
p = execution_engine.promise {}.execute
104109
assert execution_engine.waiting_work.include?(p)
105110
end
106111

test/test_promise.rb

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ module Roby
99
before do
1010
@recorder = flexmock
1111
end
12-
it "registers the promise as pending work on the engine" do
13-
p = execution_engine.promise {}
14-
assert execution_engine.waiting_work.include?(p)
15-
end
1612

1713
it "executes the promised work" do
1814
recorder.should_receive(:called).once

0 commit comments

Comments
 (0)