Skip to content

Instantly share code, notes, and snippets.

@hrom512
Created October 18, 2020 15:55
Show Gist options
  • Select an option

  • Save hrom512/fd0f6c9e8ec3dd040a5a337ca2f31607 to your computer and use it in GitHub Desktop.

Select an option

Save hrom512/fd0f6c9e8ec3dd040a5a337ca2f31607 to your computer and use it in GitHub Desktop.
Ruby 3.0 Ractor example
scheduler =
Ractor.new do
loop do
Ractor.yield Ractor.recv
end
end
workers =
8.times.map do |i|
Ractor.new(scheduler, Ractor.current) do |r_input, r_output|
while inp = r_input.take
r_output << [inp, inp ** inp]
end
end
end
TASKS = 30_000
(1..TASKS).each do |i|
scheduler << i
end
completed = 0
while completed < TASKS && res = Ractor.recv
p res.first if res.first % 1000 == 0
completed += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment