[macruby-changes] [3425] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 3 17:16:18 PST 2010


Revision: 3425
          http://trac.macosforge.org/projects/ruby/changeset/3425
Author:   ernest.prabhakar at gmail.com
Date:     2010-02-03 17:16:18 -0800 (Wed, 03 Feb 2010)
Log Message:
-----------
Add/pass Dispatch :join spec, but tag async version as 'fails'

Modified Paths:
--------------
    MacRuby/trunk/lib/dispatch/dispatch.rb
    MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb

Modified: MacRuby/trunk/lib/dispatch/dispatch.rb
===================================================================
--- MacRuby/trunk/lib/dispatch/dispatch.rb	2010-02-04 01:16:08 UTC (rev 3424)
+++ MacRuby/trunk/lib/dispatch/dispatch.rb	2010-02-04 01:16:18 UTC (rev 3425)
@@ -41,19 +41,20 @@
   
   def fork(priority=nil, &block)
     grp = Group.new
-    Dispatch.group(grp) &block
+    Dispatch.group(grp, priority) { block.call }
+    # Can't pass block directly for some reason
     return grp
   end
 
   class Group
     # Companion to +Dispatch.fork+, allowing you to +wait+ until +grp+ completes
-    # providing an API similar to that used by +Threads+
-    # if a block is given, instead uses +notify+ to call it asynchronously
+    # via an API similar to that used by +Threads+
+    # If a block is given, instead uses +notify+ to call it asynchronously
     def join(&block)
-      block_given? ? notify(&block) : wait
+      Kernel.block_given? ? self.notify(&block) : self.wait 
     end
   end
   
   module_function :queue_for, :async, :sync, :group, :wrap, :fork
 
-end
\ No newline at end of file
+end

Modified: MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb	2010-02-04 01:16:08 UTC (rev 3424)
+++ MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb	2010-02-04 01:16:18 UTC (rev 3425)
@@ -6,9 +6,7 @@
   $global = 0
   class Actee
     def initialize(s="default"); @s = s; end
-    def current_queue; Dispatch::Queue.current; end
     def delay_set(n); sleep 0.01; $global = n; end
-    def increment(v); v+1; end
     def to_s; @s; end
   end
   
@@ -70,6 +68,34 @@
       end
     end
     
+    describe :fork do
+      it "should return an Group for tracking execution of the passed block" do
+        $global = 0
+        g = Dispatch.fork { @actee.delay_set(42) }
+        $global.should == 0
+        g.should be_kind_of Dispatch::Group
+        g.wait
+        $global.should == 42      
+      end
+
+      it "should :join Synchronously to that group" do
+        $global = 0
+        g = Dispatch.fork { @actee.delay_set(42) }
+        $global.should == 0
+        g.join
+        $global.should == 42      
+      end
+
+      it "should :join Asynchronously if passed another block" do
+        $global = 0
+        g = Dispatch.fork { @actee.delay_set(42) }
+        $global.should == 0
+        g.join { }
+        $global.should == 0
+        while $global == 0 do; end
+        $global.should == 42      
+      end
+    end
     
   end
-end
\ No newline at end of file
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100203/e5e06d57/attachment.html>


More information about the macruby-changes mailing list