[macruby-changes] [3546] MacRuby/trunk/lib/dispatch/enumerable.rb

source_changes at macosforge.org source_changes at macosforge.org
Mon Feb 15 17:31:05 PST 2010


Revision: 3546
          http://trac.macosforge.org/projects/ruby/changeset/3546
Author:   ernest.prabhakar at gmail.com
Date:     2010-02-15 17:31:05 -0800 (Mon, 15 Feb 2010)
Log Message:
-----------
Mocked out Queue#apply to workaround bug (?) in Enumerable

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

Modified: MacRuby/trunk/lib/dispatch/enumerable.rb
===================================================================
--- MacRuby/trunk/lib/dispatch/enumerable.rb	2010-02-16 01:30:54 UTC (rev 3545)
+++ MacRuby/trunk/lib/dispatch/enumerable.rb	2010-02-16 01:31:05 UTC (rev 3546)
@@ -1,5 +1,18 @@
 # Additional parallel operations for any object supporting +each+
 
+module Dispatch
+  class Queue
+    def fake_apply(n, &block)
+      g = Dispatch::Group.new
+      n.times do |i|
+        async(g) { block.call(i) }
+      end
+      g.wait
+    end
+  end
+end
+
+
 class Integer
   # Applies the +&block+ +Integer+ number of times in parallel
   # -- passing in stride (default 1) iterations at a time --
@@ -18,7 +31,7 @@
     block_from = Proc.new do |j0|
       lambda { |j| block.call(j0+j) }
     end
-    q.apply(n_strides) { |i| stride.times &block_from.call(i*stride) }
+    q.fake_apply(n_strides) { |i| stride.times &block_from.call(i*stride) }
     # Runs the remainder (if any) sequentially on the current thread
     (n_times % stride).times &block_from.call(n_strides*stride)
   end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100215/45472238/attachment.html>


More information about the macruby-changes mailing list