Note that there are some explanatory texts on larger screens.

plurals
  1. POGo Channels in Ruby
    primarykey
    data
    text
    <p>In the Go programming language, you can send Messages around using a construct called "Channels". <a href="http://golang.org/doc/effective_go.html#channels" rel="noreferrer">http://golang.org/doc/effective_go.html#channels</a></p> <p>I would love to use something like that in Ruby, especially for IPC.</p> <p>Pseudocode of what I want:</p> <pre><code>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 # ~&gt; bar foo foo bar bar foo </code></pre> <p>Is there any construct, library or equivalent for Ruby which works like that ?</p> <p>If not: What is the best way to build such an abstraction?</p> <p><strong>UPDATE:</strong> To clarify what I need from these Channels. </p> <p>One use case: Some forked workers waiting for jobs. They all read from the same JobChannel and report results to the same ResultChannel. </p> <p>The Channels I need</p> <ul> <li>are very fast, </li> <li>writes do not block, <em>(message sending)</em> </li> <li>reads do block, <em>(message receiving)</em></li> <li>do not need special treatment before forking,</li> <li>lightweight and simple would be nice.</li> </ul> <p>So far I played around with </p> <ul> <li>DRb, <em>(opposite of lightweight + slow + too much magic for my little brain)</em> </li> <li>Sockets, <em>(UNIXSocket, TCPSocket ... Sockets seem to have many many ways of using them. I got a half-working channel on UNIXSockets. If you think sockets make sense, what subset of features should I look at?)</em></li> <li>Pipes. <em>(Connecting more than 2 Processes seems to be non-trivial)</em></li> </ul> <p>If any of those was already the perfect technology for my problem, please provide tutorials etc. which have more focused information on my requirements.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload