bhuga/promising-future — pull request #6 by michaeljbishop (2012-10-11 02:33:57+00:00)
Title: Adds support for passing parameters

Hello,

I made one more change that I myself needed which is support for passing parameters to either a Future or a Promise object. I wanted the behavior to match Thread.new which prevents this problem.

hello = 'hello
t = Thread.new{hello.capitalize!}
t.join # modifies the hello variable

Here's the solution:

hello = 'hello
t = Thread.new(hello){|h| h.capitalize!}
t.join # isolated from the hello variable

I needed matching behavior for Promise and Future. The changes are as follows:

- Future now only uses Thread behind the scenes. It no longer uses Promise.
- Promise saves a duplicate copy of the args passed to it and passes them to the block when __force__ is called.

I added test cases to make sure the above example works (substituting Future|Promise for Thread) and to make sure the second example works as well. Documentation has been updated to match.

Lastly, I made a small optimization so when a Promise|Future has been forced, they nil out references to data no longer needed.

I hope you find them useful. Thank you for this library.