Skip to content

Instantly share code, notes, and snippets.

@patrickt
Created December 15, 2009 14:41
Show Gist options
  • Save patrickt/256986 to your computer and use it in GitHub Desktop.
Save patrickt/256986 to your computer and use it in GitHub Desktop.
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