Skip to content

Instantly share code, notes, and snippets.

@eregon
Created October 31, 2020 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eregon/092ea76534b46e227d9cbf5fd107de66 to your computer and use it in GitHub Desktop.
Save eregon/092ea76534b46e227d9cbf5fd107de66 to your computer and use it in GitHub Desktop.
USE_MOVE = !false
receive2yield = Ractor.new do
loop do
if USE_MOVE
Ractor.yield Ractor.receive, move: true
else
Ractor.yield Ractor.receive
end
end
end
receive2send = Ractor.new receive2yield do |r|
loop do
if USE_MOVE
r.send Ractor.receive, move: true
else
r.send Ractor.receive
end
end
end
take2yield = Ractor.new receive2yield do |from|
loop do
if USE_MOVE
Ractor.yield from.take, move: true
else
Ractor.yield from.take
end
end
end
take2send = Ractor.new take2yield, Ractor.current do |from, to|
loop do
if USE_MOVE
to.send from.take, move: true
else
to.send from.take
end
end
end
AN = 1_000
LN = 10_000
ary = Array.new(AN) # 1000
# Ractor.make_shareable(ary)
LN.times{
receive2send << ary
Ractor.receive
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment