OVERVIEW

Project IProcess
Homepage https://github.com/robgleeson/IProcess
Documentation http://rubydoc.info/gems/iprocess/frames
CI Build Status
Author Rob Gleeson

DESCRIPTION

Provides a number of abstractions on top of spawning subprocesses and interprocess communication. The API is simple and supports both synchronous and asynchronous(non-blocking) types of programming. It also supports implicit interprocess communication that can be easily configured to use the serializer of your choice(default is the Marshal module).

EXAMPLES

1.

In this example three subprocesses are spawned. The return value of the block, even though executed in a subprocess, is returned to the parent process as long as it may be serialized by Marshal(or the serializer of your choice, this is configurable):

messages = IProcess.spawn(3) { {msg: "hello"} }
p messages # => [{msg: "hello"}, {msg: "hello"}, {msg: "hello"}]

2.

You can spawn a subprocess with a block or with any object that responds to #call. If you had a worker that was too complicated as a block you could try this:

class Worker
  def initialize
    @num = 1
  end

  def call
    @num + 1
  end
end
IProcess.spawn 5, Worker.new # => [2, 2, 2, 2, 2]

3.

A demo of how you would spawn two subprocesses asynchronously. Although the subprocesses are spawned asynchrounsly you can still communicate by defining a callback the subprocess can call when it completes. The example may not be the best, though:

class Inbox
  def recv(pid)
    puts "'#{pid}' has finished!"
  end
end
inbox = Inbox.new
IProcess.spawn!(2, inbox) { Process.pid }

SERIALIZERS

A serializer is any object that implements load & dump. You can choose what serializer you'd like to use through the IProcess.serializer= method:

IProcess.serializer = JSON

PLATFORM SUPPORT

supported

  • CRuby (1.9+)

unsupported

  • CRuby 1.8
  • MacRuby
  • JRuby
  • Rubinius (support for Rubinius will come sometime in the future).

INSTALL

$ gem install iprocess

LICENSE

MIT. See LICENSE.txt.