[macruby-changes] [3594] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Feb 23 15:27:30 PST 2010
Revision: 3594
http://trac.macosforge.org/projects/ruby/changeset/3594
Author: ernest.prabhakar at gmail.com
Date: 2010-02-23 15:27:30 -0800 (Tue, 23 Feb 2010)
Log Message:
-----------
Move Dispatch tracking from Future to Job
Modified Paths:
--------------
MacRuby/trunk/lib/dispatch.rb
MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb
Added Paths:
-----------
MacRuby/trunk/lib/dispatch/job.rb
MacRuby/trunk/spec/macruby/library/dispatch/job_spec.rb
Removed Paths:
-------------
MacRuby/trunk/lib/dispatch/future.rb
MacRuby/trunk/lib/dispatch/group.rb
MacRuby/trunk/spec/macruby/library/dispatch/future_spec.rb
MacRuby/trunk/spec/macruby/library/dispatch/group_spec.rb
Deleted: MacRuby/trunk/lib/dispatch/future.rb
===================================================================
--- MacRuby/trunk/lib/dispatch/future.rb 2010-02-23 23:27:18 UTC (rev 3593)
+++ MacRuby/trunk/lib/dispatch/future.rb 2010-02-23 23:27:30 UTC (rev 3594)
@@ -1,29 +0,0 @@
-module Dispatch
-
- # Track completion and return values of asynchronous requests
- # Duck-type +join+ and +value+ from +Thread+
- class Job
- # Create a Job that asynchronously dispatches the block
- attr_accessor :group
-
- def initialize(priority = nil, &block)
- @value = nil
- @group = Dispatch.group(nil, priority) { @value = block.call }
- end
-
- # Waits for the computation to finish, or calls block (if present) when done
- def join(&block)
- group.join(&block)
- end
-
- # 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 = Dispatch::Queue.concurrent, &callback)
- return group.notify(queue) { callback.call(@value) } if not callback.nil?
- group.wait
- return @value
- end
- end
-
-end
Deleted: MacRuby/trunk/lib/dispatch/group.rb
===================================================================
--- MacRuby/trunk/lib/dispatch/group.rb 2010-02-23 23:27:18 UTC (rev 3593)
+++ MacRuby/trunk/lib/dispatch/group.rb 2010-02-23 23:27:30 UTC (rev 3594)
@@ -1,19 +0,0 @@
-# Provide an easy, uniform wrapper around +wait+ and +notify+
-
-module Dispatch
- # Extend Dispatch::Group
-
- # Implements "join" in Group for compatibility with Future
- # TODO: make Future a subclass of Group
- # Currently not possible: https://www.macruby.org/trac/ticket/613
- class Group
- # Waits for the group to complete
- # If a block is specified, call on the specified queue or priority, if any
- def join(queue = Dispatch::Queue.concurrent, &block)
- return wait if block.nil?
- queue = Dispatch::Queue.concurrent(queue) if not queue.is_a? Dispatch::Queue #i.e., a priority
- notify(queue) { block.call }
- end
- end
-
-end
Copied: MacRuby/trunk/lib/dispatch/job.rb (from rev 3593, MacRuby/trunk/lib/dispatch/future.rb)
===================================================================
--- MacRuby/trunk/lib/dispatch/job.rb (rev 0)
+++ MacRuby/trunk/lib/dispatch/job.rb 2010-02-23 23:27:30 UTC (rev 3594)
@@ -0,0 +1,30 @@
+module Dispatch
+
+ # Track completion and return values of asynchronous requests
+ # Duck-type +join+ and +value+ from +Thread+
+ class Job
+ # Create a Job that asynchronously dispatches the block
+ attr_accessor :group
+
+ def initialize(queue = Dispatch::Queue.concurrent, &block)
+ @value = nil
+ @group = Group.new
+ queue.async(@group) { @value = block.call }
+ end
+
+ # Waits for the computation to finish, or calls block (if present) when done
+ def join(&block)
+ group.join(&block)
+ end
+
+ # 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 = Dispatch::Queue.concurrent, &callback)
+ return group.notify(queue) { callback.call(@value) } if not callback.nil?
+ group.wait
+ return @value
+ end
+ end
+
+end
Modified: MacRuby/trunk/lib/dispatch.rb
===================================================================
--- MacRuby/trunk/lib/dispatch.rb 2010-02-23 23:27:18 UTC (rev 3593)
+++ MacRuby/trunk/lib/dispatch.rb 2010-02-23 23:27:30 UTC (rev 3594)
@@ -15,6 +15,6 @@
require 'dispatch/actor'
require 'dispatch/dispatch'
require 'dispatch/enumerable'
-require 'dispatch/future'
-require 'dispatch/group'
+require 'dispatch/job'
+require 'dispatch/queue'
require 'dispatch/queue_source'
Modified: MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb 2010-02-23 23:27:18 UTC (rev 3593)
+++ MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb 2010-02-23 23:27:30 UTC (rev 3594)
@@ -26,11 +26,11 @@
end
describe :fork do
- it "should return a Future for tracking execution of the passed block" do
+ it "should return a Job for tracking execution of the passed block" do
$dispatch_gval = 0
g = Dispatch.fork { @actee.delay_set(42) }
$dispatch_gval.should == 0
- g.should be_kind_of Dispatch::Future
+ g.should be_kind_of Dispatch::Job
g.join
$dispatch_gval.should == 42
end
Deleted: MacRuby/trunk/spec/macruby/library/dispatch/future_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/library/dispatch/future_spec.rb 2010-02-23 23:27:18 UTC (rev 3593)
+++ MacRuby/trunk/spec/macruby/library/dispatch/future_spec.rb 2010-02-23 23:27:30 UTC (rev 3594)
@@ -1,52 +0,0 @@
-require File.dirname(__FILE__) + "/../../spec_helper"
-require 'dispatch'
-
-if MACOSX_VERSION >= 10.6
- describe "Dispatch::Future" do
-
- before :each do
- @result = 0
- @future = Dispatch::Future.new { sleep 0.01; @result = Math.sqrt(2**10) }
- end
-
- describe :new do
- it "should return a Future for tracking execution of the passed block" do
- @future.should be_kind_of Dispatch::Future
- end
-
- it "should take a +priority+ for which concurrent queue to use" do
- future = Dispatch::Future.new(:high) { @result=Dispatch::Queue.current }
- future.join
- @result.to_s.should == Dispatch::Queue.concurrent(:high).to_s
- end
- end
-
- describe :group do
- it "should return an instance of Dispatch::Group" do
- @future.group.should be_kind_of Dispatch::Group
- end
- end
-
- describe :join do
- it "should wait until execution is complete" do
- @result.should == 0
- @future.join
- @result.should == 2**5
- end
- end
-
- describe :value do
- it "should return value when called Synchronously" do
- @future.value.should == 2**5
- end
-
- it "should invoke passed block Asynchronously with return value" do
- @fval = 0
- @future.value {|v| @fval = v}
- while @fval == 0 do; end
- @fval.should == 2**5
- end
- end
-
- end
-end
\ No newline at end of file
Deleted: MacRuby/trunk/spec/macruby/library/dispatch/group_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/library/dispatch/group_spec.rb 2010-02-23 23:27:18 UTC (rev 3593)
+++ MacRuby/trunk/spec/macruby/library/dispatch/group_spec.rb 2010-02-23 23:27:30 UTC (rev 3594)
@@ -1,37 +0,0 @@
-require File.dirname(__FILE__) + "/../../spec_helper"
-require 'dispatch'
-
-if MACOSX_VERSION >= 10.6
- describe "Dispatch::Group" do
-
- before :each do
- @q = Dispatch::Queue.new('org.macruby.gcd_spec.group')
- @g = Dispatch::Group.new
- @i = 0
- end
-
- describe :join do
- it "should wait until execution is complete if no block is passed" do
- @q.async(@g) { @i = 42 }
- @g.join
- @i.should == 42
- end
-
- it "should run a notify block on completion, if passed" do
- @q.async(@g) { @i = 42 }
- @g.join {@i *= 2}
- while @i <= 42 do; end
- @i.should == 84
- end
-
- it "should run notify block on specified queue, if any" do
- @q.async(@g) { @i = 42 }
- @q.sync { }
- @g.join(@q) {@i *= 2}
- @q.sync { }
- @i.should == 84
- end
- end
-
- end
-end
Added: MacRuby/trunk/spec/macruby/library/dispatch/job_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/library/dispatch/job_spec.rb (rev 0)
+++ MacRuby/trunk/spec/macruby/library/dispatch/job_spec.rb 2010-02-23 23:27:30 UTC (rev 3594)
@@ -0,0 +1,67 @@
+require File.dirname(__FILE__) + "/../../spec_helper"
+require 'dispatch'
+
+if MACOSX_VERSION >= 10.6
+ describe "Dispatch::Job" do
+
+ before :each do
+ @result = 0
+ @job = Dispatch::Job.new { sleep 0.01; @result = Math.sqrt(2**10) }
+ end
+
+ describe :new do
+ it "should return a Job for tracking execution of the passed block" do
+ @job.should be_kind_of Dispatch::Job
+ end
+
+ it "should take a +priority+ for which concurrent queue to use" do
+ Job = Dispatch::Job.new(:high) { @result=Dispatch::Queue.current }
+ Job.join
+ @result.to_s.should == Dispatch::Queue.concurrent(:high).to_s
+ end
+ end
+
+ describe :group do
+ it "should return an instance of Dispatch::Group" do
+ @job.group.should be_kind_of Dispatch::Group
+ end
+ end
+
+ describe :join do
+ it "should wait until execution is complete if no block is passed" do
+ @q.async(@g) { @i = 42 }
+ @g.join
+ @i.should == 42
+ end
+
+ it "should run a notify block on completion, if passed" do
+ @q.async(@g) { @i = 42 }
+ @g.join {@i *= 2}
+ while @i <= 42 do; end
+ @i.should == 84
+ end
+
+ it "should run notify block on specified queue, if any" do
+ @q.async(@g) { @i = 42 }
+ @q.sync { }
+ @g.join(@q) {@i *= 2}
+ @q.sync { }
+ @i.should == 84
+ end
+ end
+
+ describe :value do
+ it "should return value when called Synchronously" do
+ @job.value.should == 2**5
+ end
+
+ it "should invoke passed block Asynchronously with return value" do
+ @fval = 0
+ @job.value {|v| @fval = v}
+ while @fval == 0 do; end
+ @fval.should == 2**5
+ end
+ 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/20100223/b98a4ba6/attachment-0001.html>
More information about the macruby-changes
mailing list