[macruby-changes] [3087] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Dec 7 22:47:24 PST 2009
Revision: 3087
http://trac.macosforge.org/projects/ruby/changeset/3087
Author: lsansonetti at apple.com
Date: 2009-12-07 22:47:24 -0800 (Mon, 07 Dec 2009)
Log Message:
-----------
follow GCD changes
Modified Paths:
--------------
MacRuby/trunk/spec/macruby/core/gcd_spec.rb
MacRuby/trunk/test_vm/gcd.rb
Modified: MacRuby/trunk/spec/macruby/core/gcd_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd_spec.rb 2009-12-08 06:47:03 UTC (rev 3086)
+++ MacRuby/trunk/spec/macruby/core/gcd_spec.rb 2009-12-08 06:47:24 UTC (rev 3087)
@@ -48,12 +48,12 @@
it "should return the parent queue when inside an executing block" do
q = Dispatch::Queue.new('org.macruby.rubyspecs.gcd.test')
- q2 = nil
- q.dispatch do
- q2 = Dispatch::Queue.current
+ @q2 = nil
+ q.async do
+ @q2 = Dispatch::Queue.current
end
- q.dispatch(:true) {}
- q.label.should == q2.label
+ q.sync {}
+ q.label.should == @q2.label
end
end
@@ -74,38 +74,55 @@
end
end
- describe "Dispatch::Queue#dispatch" do
+ describe "Dispatch::Queue#async" do
it "accepts a block and yields it asynchronously" do
o = Dispatch::Queue.new('foo')
- i = 0
- o.dispatch { i = 42 }
- while i == 0 do; end
- i.should == 42
+ @i = 0
+ o.async { @i = 42 }
+ while @i == 0 do; end
+ @i.should == 42
end
- it "accepts a block and yields it synchronously if the given argument is true" do
+ it "accepts a block and yields it asynchronously through a group if given" do
o = Dispatch::Queue.new('foo')
- i = 0
- o.dispatch(true) { i = 42 }
- i.should == 42
+ g = Dispatch::Group.new
+ @i = 0
+ o.async(g) { @i = 42 }
+ g.wait
+ @i.should == 42
+
+ lambda { o.async(42) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if no block is given" do
o = Dispatch::Queue.new('foo')
- lambda { o.dispatch }.should raise_error(ArgumentError)
- lambda { o.dispatch(true) }.should raise_error(ArgumentError)
+ lambda { o.async }.should raise_error(ArgumentError)
end
end
+ describe "Dispatch::Queue#sync" do
+ it "accepts a block and yields it synchronously" do
+ o = Dispatch::Queue.new('foo')
+ @i = 0
+ o.sync { @i = 42 }
+ @i.should == 42
+ end
+
+ it "raises an ArgumentError if no block is given" do
+ o = Dispatch::Queue.new('foo')
+ lambda { o.sync }.should raise_error(ArgumentError)
+ end
+ end
+
describe "Dispatch::Queue#apply" do
it "accepts an input size and a block and yields it as many times" do
o = Dispatch::Queue.new('foo')
- i = 0
- o.apply(10) { i += 1 }
- i.should == 10
- i = 42
- o.apply(0) { i += 1 }
- i.should == 42
+ @i = 0
+ o.apply(10) { @i += 1 }
+ @i.should == 10
+ @i = 42
+ o.apply(0) { @i += 1 }
+ @i.should == 42
lambda { o.apply(nil) {} }.should raise_error(TypeError)
end
@@ -119,14 +136,14 @@
describe "Dispatch::Queue#after" do
it "accepts a given time (in seconds) and a block and yields it after" do
o = Dispatch::Queue.new('foo')
- i = 0
+ @i = 0
t = Time.now
- o.after(0.2) { i = 42 }
- while i == 0 do; end
+ o.after(0.2) { @i = 42 }
+ while @i == 0 do; end
t2 = Time.now - t
t2.should >= 0.2
t2.should < 0.5
- i.should == 42
+ @i.should == 42
lambda { o.after(nil) {} }.should raise_error(TypeError)
end
@@ -150,7 +167,7 @@
describe "Dispatch::Queue#suspend!" do
it "suspends the queue which can be resumed by calling #resume!" do
o = Dispatch::Queue.new('foo')
- o.dispatch { sleep 1 }
+ o.async { sleep 1 }
o.suspended?.should == false
o.suspend!
o.suspended?.should == true
@@ -165,38 +182,10 @@
@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
+end
Modified: MacRuby/trunk/test_vm/gcd.rb
===================================================================
--- MacRuby/trunk/test_vm/gcd.rb 2009-12-08 06:47:03 UTC (rev 3086)
+++ MacRuby/trunk/test_vm/gcd.rb 2009-12-08 06:47:24 UTC (rev 3087)
@@ -2,76 +2,76 @@
# sequential + synchronous
assert n, %{
- n = 0
+ @n = 0
q = Dispatch::Queue.new('foo')
10000.times do |i|
- q.dispatch(true) { n += i }
+ q.sync { @n += i }
end
- p n
+ p @n
}
# sequential + asynchronous
assert n, %{
- n = 0
+ @n = 0
q = Dispatch::Queue.new('foo')
10000.times do |i|
- q.dispatch { n += i }
+ q.async { @n += i }
end
- q.dispatch(true) {}
- p n
+ q.sync {}
+ p @n
}
# group + sequential
assert n, %{
- n = 0
+ @n = 0
q = Dispatch::Queue.new('foo')
g = Dispatch::Group.new
10000.times do |i|
- g.dispatch(q) { n += i }
+ q.async(g) { @n += i }
end
g.wait
- p n
+ p @n
}
# group + concurrent
assert n, %{
- n = 0
+ @n = 0
q = Dispatch::Queue.new('foo')
g = Dispatch::Group.new
10000.times do |i|
- g.dispatch(Dispatch::Queue.concurrent) do
- q.dispatch(true) { n += i }
+ Dispatch::Queue.concurrent.async(g) do
+ q.sync { @n += i }
end
end
g.wait
- p n
+ p @n
}
# apply + sequential
assert n, %{
- n = 0
+ @n = 0
q = Dispatch::Queue.new('foo')
q.apply(10000) do |i|
- n += i
+ @n += i
end
- p n
+ p @n
}
# apply + concurrent
assert n, %{
- n = 0
+ @n = 0
q = Dispatch::Queue.new('foo')
Dispatch::Queue.concurrent.apply(10000) do |i|
- q.dispatch { n += i }
+ q.async { @n += i }
end
- q.dispatch(true) {}
- p n
+ q.sync {}
+ p @n
}
# exceptions should be ignored
assert ':ok', %{
g = Dispatch::Group.new
- g.dispatch(Dispatch::Queue.concurrent) { raise('hey') }
+ Dispatch::Queue.concurrent.async(g) { raise('hey') }
g.wait
p :ok
}
@@ -87,7 +87,7 @@
i = 0
g = Dispatch::Group.new
while i < 100000
- g.dispatch(Dispatch::Queue.concurrent) { i+2*3/4-5 }
+ Dispatch::Queue.concurrent.async(g) { i+2*3/4-5 }
i += 1
end
g.wait
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091207/05208565/attachment.html>
More information about the macruby-changes
mailing list