Future implements the future concept from IO. A future is an object that you create now, but which only gets a usable value in the future. Think of asynchronous messaging and long-lasting method calls.
An example:
f = Future.new { sleep 5; 123} puts f * 5 #=> 615
This future will take 5 seconds to run, then 123 is returned. The call to f.* will block until the future has a return value.
Another example:
f1 = Future.new { sleep 5; 10} f2 = Future.new { sleep 3; 20} f3 = Future.new { sleep 1; 30} puts f3 + f2 + f1
Here it only takes 5 seconds to calculate the sum instead of the 9 it would take when done sequentially.
-
Cleared up the docs a little
-
Futures can take arguments and pass them to their Thread
-
Docfix: fixed typo
-
Replaced Future Module with Future class. The old syntax is no longer supported.
-
Replaced one-time use of eval with undef_method.
-
Added specs
-
Created project
-
Added first version of future.rb, wrapped in a Module
-
Added documentation
From the project root, use rake to install.
git clone http://github.com/Narnach/future cd future rake install
This will build the gem and install it for you.
future was created by Wes Oldenbeuving. It is licensed under the MIT license.