Git Product home page Git Product logo

ichannel's Introduction

OVERVIEW

Project IChannel
Homepage https://github.com/robgleeson/ichannel
Documentation http://rubydoc.info/gems/ichannel/frames
CI Build Status
Author Robert Gleeson

DESCRIPTION

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.

EXAMPLES

1.

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 JSON or YAML.

channel = IChannel.new Marshal
pid = fork do 
  channel.put Process.pid
  channel.put 'Hello!'
end
Process.wait pid
channel.get # => Fixnum
channel.get # => 'Hello!'

SERIALIZERS

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 .dump & .load it can be passed as a serializer to IChannel.

REAL WORLD EXAMPLES

I am using IChannel in a couple of my own personal projects:

  • IProcess
    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.

  • xpool
    A lightweight UNIX(X) process pool implementation.

Other people have started to write code on top of ichannel, too:

  • ifuture
    An implementation of Futures for Ruby using process forks and ichannel.

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 ichannel

LICENSE

MIT. See LICENSE.txt.

ichannel's People

Contributors

havenwood avatar phlipper avatar tenderlove avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.