Created
February 25, 2026 03:46
-
-
Save epitron/7d8d2a6cd7ee7903a6377e3637249f16 to your computer and use it in GitHub Desktop.
Ractor::Port Fan-Out: One Producer, Many Workers
This file contains hidden or 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
| tasks = Ractor::Port.new | |
| results = Ractor::Port.new | |
| workers = 4.times.map do | |
| Ractor.new(tasks, results) do |t, r| | |
| loop do | |
| job = t.receive | |
| r.send(job * job) | |
| end | |
| end | |
| end | |
| 10.times { |i| tasks.send(i) } | |
| 10.times { puts results.receive } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment