-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select: fix case when select send executed before select receive, fixed
- v0.24.1
- 1.15.1
- 1.15.0
- 1.14.1
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- 0.36.1
- 0.36.0
- 0.35.1
- 0.35.0
- 0.34.0
- 0.33.0
- 0.32.1
- 0.32.0
- 0.31.1
- 0.31.0
- 0.30.1
- 0.30.0
- 0.29.0
- 0.28.0
- 0.27.2
- 0.27.1
- 0.27.0
- 0.26.1
- 0.26.0
- 0.25.1
- 0.25.0
- 0.24.2
- 0.24.1
- 0.24.0
- 0.23.1
- 0.23.0
Showing
2 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
require "spec" | ||
|
||
describe "select" do | ||
it "select many receviers" do | ||
ch1 = Channel(Int32).new | ||
ch2 = Channel(Int32).new | ||
res = [] of Int32 | ||
spawn do | ||
10.times do |i| | ||
(i % 2 == 0) ? ch1.send(i) : ch2.send(i) | ||
end | ||
end | ||
|
||
10.times do | ||
select | ||
when x = ch1.receive | ||
res << x | ||
when y = ch2.receive | ||
res << y | ||
end | ||
end | ||
res.should eq (0...10).to_a | ||
end | ||
|
||
it "select many senders" do | ||
ch1 = Channel(Int32).new | ||
ch2 = Channel(Int32).new | ||
res = [] of Int32 | ||
spawn do | ||
5.times { res << ch1.receive } | ||
end | ||
|
||
spawn do | ||
5.times { res << ch2.receive } | ||
end | ||
|
||
10.times do |i| | ||
select | ||
when ch1.send(i) | ||
when ch2.send(i) | ||
end | ||
end | ||
res.should eq (0...10).to_a | ||
end | ||
|
||
it "select many receivers, senders" do | ||
ch1 = Channel(Int32).new | ||
ch2 = Channel(Int32).new | ||
res = [] of Int32 | ||
spawn do | ||
10.times do |i| | ||
select | ||
when x = ch1.receive | ||
res << x | ||
when ch2.send(i) | ||
end | ||
end | ||
end | ||
|
||
10.times do |i| | ||
select | ||
when ch1.send(i) | ||
when y = ch2.receive | ||
res << y | ||
end | ||
end | ||
res.should eq (0...10).to_a | ||
end | ||
|
||
it "select should work with send which started before receive, fixed #3862" do | ||
ch1 = Channel(Int32).new | ||
ch2 = Channel(Int32).new | ||
|
||
spawn do | ||
select | ||
when ch1.send(1) | ||
when ch2.receive | ||
end | ||
end | ||
|
||
x = nil | ||
|
||
spawn do | ||
select | ||
when a = ch1.receive | ||
x = a | ||
when b = ch2.receive | ||
x = b | ||
end | ||
end | ||
|
||
Fiber.yield | ||
|
||
x.should eq 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters