In the Go programming language, you can send Messages around using a construct called "Channels". http://golang.org/doc/effective_go.html#channels
I would love to use something like that in Ruby, especially for IPC.
Pseudocode of what I want:
channel = Channel.new
fork do
3.times{ channel.send("foo ") }
exit!
end
Thread.new do
3.times{ channel.send("bar ") }
end
loop do
print channel.recv
end
# ~> bar foo foo bar bar foo
Is there any construct, library or equivalent for Ruby which works like that ?
If not: What is the best way to build such an abstraction?
UPDATE: To clarify what I need from these Channels.
One use case: Some forked workers waiting for jobs. They all read from the same JobChannel and report results to the same ResultChannel.
The Channels I need
So far I played around with
If any of those was already the perfect technology for my problem, please provide tutorials etc. which have more focused information on my requirements.
Go's idea of message passing via channels, as a first-class construct, really only makes sense in the presence of concurrency (goroutines, tasklets, whatever you'd care to call them). With cheap concurrency, blocking a tasklet or coroutine is no longer a problem, and blocking message passing starts to make a lot more sense.
If this were Python, I'd point you at Stackless; in Ruby, perhaps Revactor or NeverBlock fit the bill for you?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With