[macruby-changes] [3263] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jan 13 15:02:54 PST 2010
Revision: 3263
http://trac.macosforge.org/projects/ruby/changeset/3263
Author: ernest.prabhakar at gmail.com
Date: 2010-01-13 15:02:53 -0800 (Wed, 13 Jan 2010)
Log Message:
-----------
Updated Dispatch::Queue#after source and specs to match and work
Modified Paths:
--------------
MacRuby/trunk/gcd.c
MacRuby/trunk/spec/macruby/core/gcd/queue_spec.rb
Modified: MacRuby/trunk/gcd.c
===================================================================
--- MacRuby/trunk/gcd.c 2010-01-13 23:02:51 UTC (rev 3262)
+++ MacRuby/trunk/gcd.c 2010-01-13 23:02:53 UTC (rev 3263)
@@ -445,17 +445,17 @@
/*
* call-seq:
- * gcdq.after(time) { block }
+ * gcdq.after(delay) { block }
*
- * Runs the passed block after the given time (in seconds).
+ * Runs the passed block after the given delay (in seconds).
*
* gcdq.after(0.5) { puts 'wait is over :)' }
*
*/
static VALUE
-rb_queue_dispatch_after(VALUE self, SEL sel, VALUE sec)
+rb_queue_dispatch_after(VALUE self, SEL sel, VALUE delay)
{
- dispatch_time_t offset = rb_num2timeout(sec);
+ dispatch_time_t offset = NIL_P(delay) ? DISPATCH_TIME_NOW : rb_num2timeout(delay);
rb_vm_block_t *block = given_block();
block = rb_dispatch_prepare_block(block);
@@ -786,12 +786,12 @@
{
Check_Queue(queue);
rb_source_t *src = RSource(self);
- dispatch_source_type_t type = rb_num2source_type(type);
- assert(type != NULL);
+ dispatch_source_type_t c_type = rb_num2source_type(type);
+ assert(c_type != NULL);
uintptr_t c_handle = NUM2UINT(handle);
unsigned long c_mask = NUM2LONG(mask);
dispatch_queue_t c_queue = RQueue(queue)->queue;
- src->source = dispatch_source_create(type, c_handle, c_mask, c_queue);
+ src->source = dispatch_source_create(c_type, c_handle, c_mask, c_queue);
assert(src->source != NULL);
if (rb_block_given_p()) {
Modified: MacRuby/trunk/spec/macruby/core/gcd/queue_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd/queue_spec.rb 2010-01-13 23:02:51 UTC (rev 3262)
+++ MacRuby/trunk/spec/macruby/core/gcd/queue_spec.rb 2010-01-13 23:02:53 UTC (rev 3263)
@@ -119,24 +119,31 @@
end
describe :after do
- it "accepts a given time (in seconds) and a block and yields it after" do
- [0.02].each do |test_time|
+ it "accepts a given delay (in seconds) and a block and yields it after" do
+ [0.02].each do |delay|
t = Time.now
- @q.after(test_time) { @i = 42 }
+ @q.after(delay) { @i = 42 }
@i = 0
while @i == 0 do; end
@i.should == 42
t2 = Time.now - t
- t2.should > test_time
- t2.should < test_time*2
+ t2.should > delay
+ t2.should < delay*2
end
end
- it "raises TypeError if no time is given" do
- lambda { @q.after(nil) {} }.should raise_error(TypeError)
+ it "runs immediately if nil delay is given" do
+ @i = 0
+ @q.after(nil) { @i = 42 }
+ @q.sync {}
+ @i.should == 42
end
+ it "raises TypeError if no number is given" do
+ lambda { @q.after("string") {} }.should raise_error(TypeError)
+ end
+
it "raises an ArgumentError if no block is given" do
lambda { @q.after(42) }.should raise_error(ArgumentError)
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100113/28d3ace2/attachment-0001.html>
More information about the macruby-changes
mailing list