[macruby-changes] [3538] MacRuby/trunk/lib/dispatch/future.rb

source_changes at macosforge.org source_changes at macosforge.org
Mon Feb 15 17:29:43 PST 2010


Revision: 3538
          http://trac.macosforge.org/projects/ruby/changeset/3538
Author:   ernest.prabhakar at gmail.com
Date:     2010-02-15 17:29:43 -0800 (Mon, 15 Feb 2010)
Log Message:
-----------
Streamline Dispatch::Future using default values

Modified Paths:
--------------
    MacRuby/trunk/lib/dispatch/future.rb

Modified: MacRuby/trunk/lib/dispatch/future.rb
===================================================================
--- MacRuby/trunk/lib/dispatch/future.rb	2010-02-16 01:29:34 UTC (rev 3537)
+++ MacRuby/trunk/lib/dispatch/future.rb	2010-02-16 01:29:43 UTC (rev 3538)
@@ -3,7 +3,7 @@
 module Dispatch
   # Wrap Dispatch::Group to implement lazy Futures
   # By duck-typing Thread +join+ and +value+
-   
+  
   class Future
     # Create a future that asynchronously dispatches the block 
     # to a concurrent queue of the specified (optional) +priority+
@@ -23,15 +23,11 @@
     # Joins, then returns the value
     # If a block is passed, invoke that asynchronously with the final value
     # on the specified +queue+ (or else the default queue).
-    def value(queue = nil, &callback)
-      if not block_given?
-        group.wait
-        return @value
-      else
-        queue ||= Dispatch::Queue.concurrent
-        group.notify(queue) { callback.call(@value) }
-      end
-    end   
+    def value(queue = Dispatch::Queue.concurrent, &callback)
+      return group.notify(queue) { callback.call(@value) } if not callback.nil?
+      group.wait
+      return @value
+    end
   end
 
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100215/90cb1412/attachment.html>


More information about the macruby-changes mailing list