Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'bendiken/master'

  • Loading branch information...
commit 7f444f6d60ab1305556fd99b631d0cf8c4caa1a5 2 parents a4641fe + 6f23781
@bhuga authored
View
8 .gemspec
@@ -10,8 +10,8 @@ GEMSPEC = Gem::Specification.new do |gem|
gem.license = 'Public Domain' if gem.respond_to?(:license=)
gem.summary = 'Promises and futures for Ruby'
gem.description = <<-EOF
- A glimpse into a promising future, in which ruby supports delayed execution.
- Provides 'promise' and 'future' functions.
+ A glimpse of a promising future in which Ruby supports delayed execution.
+ Provides global 'promise' and 'future' methods.
EOF
gem.rubyforge_project = 'promising-future'
@@ -30,7 +30,7 @@ GEMSPEC = Gem::Specification.new do |gem|
gem.required_ruby_version = '>= 1.8.2'
gem.requirements = []
- gem.add_development_dependency 'rspec', '>= 1.2.9'
- gem.add_development_dependency 'yard' , '>= 0.5.2'
+ gem.add_development_dependency 'rspec', '>= 1.3.0'
+ gem.add_development_dependency 'yard' , '>= 0.5.6'
gem.post_install_message = nil
end
View
6 .gitignore
@@ -1,4 +1,8 @@
+.DS_Store
+.tmp
+.yardoc
doc
coverage
+pkg
+tmp
*.gem
-.yardoc
View
11 .yardopts
@@ -0,0 +1,11 @@
+--title "Promises and Futures for Ruby"
+--output-dir doc/yard
+--protected
+--no-private
+--hide-void-return
+--markup markdown
+--readme README.md
+-
+AUTHORS
+UNLICENSE
+VERSION
View
40 README.md
@@ -1,26 +1,27 @@
# Promising Future
-A glimpse of a promising future in which ruby supports delayed execution
+A glimpse of a promising future in which Ruby supports delayed execution.
## 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
-
+ require 'future' # you can just require 'future' if using both
+
x = promise { 1 + 2 }
- y = future { sleep 10; 5 + 5 }
-
- puts x # => 3
- # ... do work for 5 seconds
- puts y # => 10, after blocking 5 seconds
-
-Promises and futures both transparantly delay the execution of a block.
-Futures run the evaluation of the block optimistically in another thread.
+ 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 irb, which will evaluate everything
-as part of its read-eval-print loop.
+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.
-Yardocs are available at <http://promise.rubyforge.org/>. Tested under MRI
-1.8 and JRuby.
+The library has been tested with Ruby 1.8.7, 1.9.1 and JRuby 1.5.0.
+YARD documentation is available at <http://promise.rubyforge.org/>
## Classes
@@ -28,17 +29,18 @@ Yardocs are available at <http://promise.rubyforge.org/>. Tested under MRI
* {Future}
## Installation
+The library is distributed via [RubyGems](http://rubygems.org/):
-Promising future is distributed via gemcutter under the name 'promise'.
-
- gem install promise
+ $ gem install promise
## Source
The source is available at <http://github.com/bhuga/promising-future>
## Author
-Ben Lavender (http://github.com/bhuga)
+[Ben Lavender](http://github.com/bhuga)
## 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
View
8 lib/future.rb
@@ -6,11 +6,11 @@
# x = future { sleep 5; 1 + 2 }
# # do stuff...
# y = x * 2 # => 6. blocks unless 5 seconds has passed.
-#
+#
class Future < defined?(BasicObject) ? BasicObject : Object
instance_methods.each { |m| undef_method m unless m =~ /__|object_id/ } unless defined?(BasicObject)
-
+
##
# @param [Proc] block
# @return [Future]
@@ -31,7 +31,7 @@ def force
# @private
def method_missing(method, *args, &block)
- @promise.send(method, *args, &block)
+ @promise.send(method, *args, &block)
end
@@ -40,7 +40,7 @@ def method_missing(method, *args, &block)
module Kernel
- # Create a new future
+ # Create a new future
# @example
# x = future { 3 + 3 }
def future(&block)
View
4 lib/promise.rb
@@ -29,7 +29,7 @@ def initialize(block)
# Force the evaluation of this promise immediately
# @return [Any]
def force
- @mutex.synchronize do
+ @mutex.synchronize do
unless @result
@result = @block.call
end
@@ -44,7 +44,7 @@ def method_missing(method, *args, &block)
end
module Kernel
-
+
# Create a new promise
# @example
# x = promise { 3 + 3 }
Please sign in to comment.
Something went wrong with that request. Please try again.