New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add specs for Promise#zip/Promise.zip ordering #660
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't rely on sleep
for thread synchronization and ordering. Use concurrency primitives instead.
it 'preserves ordering of the executed promises' do | ||
promise1 = Promise.execute do | ||
# resolves after the second promise | ||
sleep 0.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't rely on sleep
for thread synchronization/ordering. Instead use concurrency primites:
running = Mutex.new
cond = ConditionVariable.new
cond2 = ConditionVariable.new
p1 = Concurrent::Promise.execute do
running.synchronize {
cond.wait(running)
'one'
}
end
p2 = Concurrent::Promise.execute do
running.synchronize {
cond2.wait(running)
'two'
}
end
p3 = Concurrent::Promise.execute do
running.synchronize {
'three'
}
end
cond2.signal
cond.signal
result = Concurrent::Promise.zip(p1, p2, p3).value
expect(result) .to eq(['one', 'two', 'three'])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
64009ad
to
84f4591
Compare
@ianks could you use |
84f4591
to
8720d17
Compare
I've updated the PR to use count-down-latch and rebased. |
I noticed there were not any specs on the ordering of
Promise.zip
. Since it is part of the spec (as it applies toPromise.all
), I figured I could add some tests for that.For more info: https://stackoverflow.com/a/28066851