Project

promise

0.05
No commit activity in last 3 years
No release in over 3 years
A glimpse of a promising future in which Ruby supports delayed execution. Provides global 'promise' and 'future' methods.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.3.0
>= 0.5.8
 Project Readme

Promising Future

A glimpse of a promising future in which Ruby supports lazy evaluation.

Overview

Promises and futures both transparently defer the execution of a block. Promises evaluate the given block if and when its result is first needed. Futures evaluate the given block optimistically in another thread.

    require 'promise'
    require 'future'    # you can just require 'future' if using both

    x = promise { 1 + 2 }
    y = future  { sleep(10) && 6 * 7 }

    puts x      #=> 3
    sleep 5     # ... do work for 5 seconds ...
    puts y      #=> 42, after blocking 5 seconds

Note that this is pretty useless in Ruby's interactive shell irb, as it will eagerly evaluate everything as part of its read-eval-print loop, forcing promises and futures to yield their results.

If you still want to test in irb you can try something like this:

    x = promise { sleep(5) && 6 * 7 }; nil
    # do some work
    x + 1 # block for 5 seconds

The library is automatically tested with Travis CI and aims to support a wide range of Ruby interpreters.

Build Status Coverage Status

YARD documentation is available at http://promise.rubyforge.org/

Classes

  • {Promise}
  • {Future}

Installation

The library is distributed via RubyGems:

    $ gem install promise

Source

The source is available at http://github.com/bhuga/promising-future

Author

Ben Lavender

Unlicense

Promising Future is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.