Created
December 15, 2009 14:41
-
-
Save patrickt/256986 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include Dispatch | |
class Future | |
def initialize(&block) | |
@@queue ||= Queue.new("org.macruby.futures") | |
@group = Group.new | |
@@queue.async(@group) { @value = block[] } | |
end | |
def value | |
@group.wait | |
@value | |
end | |
end | |
f = Future.new do | |
sleep 2.5 | |
'some value' | |
end | |
p f.value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment