Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Futures over IPC - Deprecated
Ruby
tag: v0.3.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
ifuture.gemspec

README.md

iFuture

Build Status Code Climate

A Futures gem for Ruby implemented with IChannel for interprocess communication over a unix socket or Redis. Run some code in another process and get the result back later!

The Future starts running right away, but isn't blocking because it runs in its own fork and uses IChannel to communicate with the parent Process. This allows multithreading without the GIL blocking as it would with Futures implemented on Threads. If the value is asked for and it is ready, it will be returned right away. If the value is asked for early, the Future blocks until delivery.

Installation

gem install ifuture

The Redis gem is required as well if you opt to use Redis instead of the default Unix socket transporter.

gem install redis

Usage

require 'ifuture'
future = IFuture.unix Marshal do
  sleep 2
  'Put that in your unix socket and smoke it'
end

future.ready? # => false
sleep 2
future.ready? # => true
future.value # => "Put that in your unix socket and smoke it"

Code Serialization Format

The default serialization format is Marshal, but you can use JSON, YAML or other formats that implement the methods #load and #dump.

require 'ifuture'
require 'json'
future = IFuture.unix JSON do
  sleep 2
  {ok: true}
end

IPC Transporter

By default iFuture uses IChannel with unix sockets for transferring serialized code. An alternate choice is to use IChannel with Redis, locally or over the network.

require 'ifuture'
future = IFuture.redis Marshal, {host: 'localhost', key: 'readme'} do
  sleep 5
  42
end
future.value # => 42

Contributing

  1. Fork it
  2. Commit your changes
  3. Create a pull request
Something went wrong with that request. Please try again.