Revision: 3453 http://trac.macosforge.org/projects/ruby/changeset/3453 Author: ernest.prabhakar@gmail.com Date: 2010-02-08 15:05:16 -0800 (Mon, 08 Feb 2010) Log Message: ----------- Enumerable::p_mapdispatch works, but may not be thread safe Modified Paths: -------------- MacRuby/trunk/lib/dispatch/enumerable.rb MacRuby/trunk/spec/macruby/library/dispatch/enumerable_spec.rb Modified: MacRuby/trunk/lib/dispatch/enumerable.rb =================================================================== --- MacRuby/trunk/lib/dispatch/enumerable.rb 2010-02-08 23:05:07 UTC (rev 3452) +++ MacRuby/trunk/lib/dispatch/enumerable.rb 2010-02-08 23:05:16 UTC (rev 3453) @@ -34,15 +34,16 @@ def p_mapreduce(result, op=:+, &block) raise ArgumentError if not result.respond_to? op # Since exceptions from a Dispatch block act funky - q = Dispatch.queue_for(result) + @result = result + q = Dispatch.queue_for(@result) self.p_each do |obj| val = block.call(obj) q.async do - result = result.send(op, val) + @result = @result.send(op, val) end end q.sync {} - result + @result end Modified: MacRuby/trunk/spec/macruby/library/dispatch/enumerable_spec.rb =================================================================== --- MacRuby/trunk/spec/macruby/library/dispatch/enumerable_spec.rb 2010-02-08 23:05:07 UTC (rev 3452) +++ MacRuby/trunk/spec/macruby/library/dispatch/enumerable_spec.rb 2010-02-08 23:05:16 UTC (rev 3453) @@ -67,8 +67,8 @@ it "should behave like an unordered map" do map1 = @ary.map {|v| v*v} - map2 = @ary.p_mapreduce([]) {|v| v*v} - map1.should == map2.sort + map2 = @ary.p_mapreduce([]) {|v| [v*v]} + map2.sort.should == map1 end it "should accumulate any object that takes :<< " do
participants (1)
-
source_changes@macosforge.org