Added: MacRuby/trunk/sample-macruby/Scripts/futures.rb (0 => 3144)
--- MacRuby/trunk/sample-macruby/Scripts/futures.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/Scripts/futures.rb 2009-12-22 16:39:08 UTC (rev 3144)
@@ -0,0 +1,22 @@
+include Dispatch
+
+class Future
+ def initialize(&block)
+ @@queue_count ||= 0
+ Thread.current[:futures_queue] ||= Queue.new("org.macruby.futures-#{Thread.current.object_id}")
+ @group = Group.new
+ Thread.current[:futures_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
\ No newline at end of file