bhuga/promising-future
{ "createdAt": "2010-01-11T12:35:07Z", "defaultBranch": "master", "description": "A glimpse of a promising future in which ruby supports delayed execution", "fullName": "bhuga/promising-future", "homepage": "", "language": "Ruby", "name": "promising-future", "pushedAt": "2017-03-21T08:46:47Z", "stargazersCount": 85, "topics": [], "updatedAt": "2023-03-31T18:59:13Z", "url": "https://github.com/bhuga/promising-future"}Promising Future
Section titled “Promising Future”A glimpse of a promising future in which Ruby supports lazy evaluation.
Overview
Section titled “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 secondsNote 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 secondsThe library is automatically tested with Travis CI and aims to support a wide range of Ruby interpreters.
YARD documentation is available at http://promise.rubyforge.org/
Classes
Section titled “Classes”- {Promise}
- {Future}
Installation
Section titled “Installation”The library is distributed via RubyGems:
$ gem install promiseSource
Section titled “Source”The source is available at http://github.com/bhuga/promising-future
Author
Section titled “Author”Unlicense
Section titled “Unlicense”Promising Future is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.
[Promises and futures] !: http://en.wikipedia.org/wiki/Futures_and_promises