[macruby-changes] [2443] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 31 02:36:37 PDT 2009


Revision: 2443
          http://trac.macosforge.org/projects/ruby/changeset/2443
Author:   mattaimonetti at gmail.com
Date:     2009-08-31 02:36:33 -0700 (Mon, 31 Aug 2009)
Log Message:
-----------
added more GCD API documentation

Modified Paths:
--------------
    MacRuby/trunk/gcd.c
    MacRuby/trunk/spec/macruby/core/gcd_spec.rb

Modified: MacRuby/trunk/gcd.c
===================================================================
--- MacRuby/trunk/gcd.c	2009-08-31 08:47:28 UTC (rev 2442)
+++ MacRuby/trunk/gcd.c	2009-08-31 09:36:33 UTC (rev 2443)
@@ -473,6 +473,21 @@
     return (VALUE)group;
 }
 
+/* 
+ *  call-seq:
+ *    Dispatch::Group.new    =>  Dispatch::Group
+ *
+ *  Returns a Queue group allowing for for aggregate synchronization.
+ *  You can dispatch multiple blocks and track when they all complete, 
+ *  even though they might run on different queues. 
+ *  This behavior can be helpful when progress can’t be made until all 
+ *  of the specified tasks are complete.
+ *
+ *  
+ *     gcdg = Dispatch::Group.new
+ *
+ */
+
 static VALUE
 rb_group_initialize(VALUE self, SEL sel)
 {
@@ -480,6 +495,23 @@
     return self;
 }
 
+/* 
+ *  call-seq:
+ *    gcdg.dispatch { block }
+ *
+ *  Yields the passed block via the group.
+ *  The dispatch group maintains a count of its outstanding associated tasks, 
+ *  incrementing the count when a new task is associated and decrementing it 
+ *  when a task completes. 
+ *
+ *  <code>#notify</code< and <code>#wait</code> use that count to determine 
+ *  when all tasks associated with the group have completed.
+ *
+ *     gcdg = Dispatch::Group.new
+ *     gcdg.dispatch { p 'foo'}
+ *
+ */
+
 static VALUE
 rb_group_dispatch(VALUE self, SEL sel, VALUE target)
 {
@@ -496,6 +528,21 @@
     return Qnil;
 }
 
+
+/* 
+ *  call-seq:
+ *    gcdg.notify { block }
+ *
+ *  Schedules a block to be called when a group of previously submitted dispatches
+ *  have completed.
+ *
+ *
+ *     gcdg = Dispatch::Group.new
+ *     gcdg.notify { p 'bar' }
+ *     gcdg.dispatch { p 'foo' }
+ *
+ */
+
 static VALUE
 rb_group_notify(VALUE self, SEL sel, VALUE target)
 {

Modified: MacRuby/trunk/spec/macruby/core/gcd_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd_spec.rb	2009-08-31 08:47:28 UTC (rev 2442)
+++ MacRuby/trunk/spec/macruby/core/gcd_spec.rb	2009-08-31 09:36:33 UTC (rev 2443)
@@ -138,4 +138,45 @@
       o.suspended?.should == false
     end
   end
+  
+  describe "Dispatch::Group" do
+    it "returns an instance of Group" do
+      @group = Dispatch::Group.new
+      @group.should be_kind_of(Dispatch::Group)
+    end
+    
+    describe "#dispatch" do
+      it "raises an ArgumentError if no block is given" do
+        lambda { @group.dispatch }.should raise_error(ArgumentError) 
+      end
+      
+      # it "accepts a block and yields it asynchronously" do
+      #   i = 0 
+      #   @group.dispatch { i = 42 }
+      #   while i == 0 do; end
+      #   i.should == 42
+      # end  
+      
+    end
+    
+    describe "#notify" do
+      it "raises an ArgumentError if no block is given" do
+        lambda { @group.dispatch }.should raise_error(ArgumentError) 
+      end
+      
+      # it "accepts a block and yields it when the group is ready" do
+      #   i = 0 
+      #   @group.notify{ i = 42}
+      #   @group.dispatch { i = 40 }
+      #   while i == 0 do; end
+      #   i.should == 42
+      # end  
+      
+    end
+    
+    describe "#wait" do
+      
+    end
+    
+  end
 end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090831/63204c6d/attachment.html>


More information about the macruby-changes mailing list