A modern, flexible & easy to use interprocess communication(IPC) primitive. The
basic premise is that you can "put" and "get" Ruby objects to/from a channel.
This works across any Ruby process & its subprocesses, though, which is why it
can be useful. You could describe putting and getting objects to/from the channel
as message passing but the message could potentially be any Ruby object,
although I think sending small messages(as a Hash) works very well for most
scenarios. You have the potential to serialize any object that
To send Ruby objects between processes they have to be serialized, but on the bright side the number of serializers to choose from is vast. Marshal, JSON, & YAML are supported out of the box to name a few but adding support for other serializers is a trivial amount of work.
For example, here is a MessagePack serializer you could use:
require 'ichannel' require 'msgpack' serializer = Class.new do def self.dump(msg) MessagePack.pack msg end def self.load(msg) MessagePack.unpack msg end end channel = IChannel.new serializer
As you can see above as long as the serializer responds to
can be passed as a serializer to IChannel.
The first example shows off how you'd pass Ruby objects through a channel.
The serializer of choice is
Marshal but it could just as easily be
channel = IChannel.new Marshal channel.put 'hello' channel.put 'goodbye' pid = fork do channel.get # => 'hello' channel.get # => 'goodbye' end Process.wait pid
REAL WORLD EXAMPLES
I am using IChannel in a couple of my own personal projects:
Provides a number of abstractions on top of spawning subprocesses and interprocess communication. IChannel was born inside IProcess but later extracted into its own project when I realised it could be useful on its own.
A UNIX(X) Process Pool.
- CRuby (1.9+)
- CRuby 1.8
- Rubinius (support for Rubinius will come sometime in the future).
$ gem install ichannel
MIT. See LICENSE.txt.