Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Futures over IPC - Deprecated
Ruby
Tag: v0.2.0

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

Futures for Ruby implemented with IChannel for interprocess communication via a UNIXSocket or Redis. Run some code in another process, locally or over the network, 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.

Usage

future = IFuture.new do
  3.downto 0 do |n|
    sleep 1
    puts "#{n}..."
  end

  'Sekret!!'
end

future.ready?
#=> false

sleep 5
#=> 5

# 3...
# 2...
# 1...
# 0...

future.ready?
#=> true

future.value
#=> "Sekret!!"

Serializer

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

require 'json'

future = IFuture.new JSON do
  sleep 5
  :human_readable
end

Transport

By default iFuture uses iChannel with unix sockets for transferring serialized code. To run your fork on a process located remoted over the network, you can specify that you want to you iChannel with Redis on a host of your choosing.

future = IFuture.new(Marshal, :redis, {host: 'localhost', key: 'readme'}) do
  sleep 5
  :over_the_wire
end

Installation

gem install ifuture

Contributing

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