-
-
Save havenwood/74c81ec76e5a2bc1b775838e21818087 to your computer and use it in GitHub Desktop.
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
r = Ractor.new do | |
# Two pipes a piping... | |
pipes = Array.new 2 do | |
Ractor.new do | |
loop do | |
Ractor.yield Ractor.receive | |
end | |
end | |
end | |
loop do | |
# Pick a pipe at random to send to... | |
pipes.sample << Ractor.receive | |
# And select a pipe to receive from... | |
_pipe, response = Ractor.select(*pipes) | |
Ractor.yield response | |
end | |
end | |
r.send :test | |
100_000.times { r.send r.take } | |
r.take | |
#=> :test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment