Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Dispatch::Source.timer does not repeat if specify TIME_FOREVER to int…

…erval. fix #1491
  • Loading branch information...
commit bcd996c558e4fe37c8e185c804c2459f57cf0709 1 parent 43d40b9
@Watson1978 Watson1978 authored
Showing with 19 additions and 3 deletions.
  1. +12 −3 gcd.c
  2. +7 −0 spec/macruby/core/gcd/source_spec.rb
View
15 gcd.c
@@ -112,6 +112,9 @@ static VALUE cGroup;
static VALUE cSource;
static VALUE cSemaphore;
+static VALUE const_time_now;
+static VALUE const_time_forever;
+
static inline void
Check_Queue(VALUE object)
{
@@ -152,6 +155,10 @@ rb_raise_init(VALUE self, SEL sel)
static inline uint64_t
rb_num2nsec(VALUE num)
{
+ if (num == const_time_forever) {
+ return DISPATCH_TIME_FOREVER;
+ }
+
const double sec = rb_num2dbl(num);
if (sec < 0.0) {
rb_raise(rb_eArgError, "negative delay specified");
@@ -1471,10 +1478,12 @@ Init_Dispatch(void)
* dispatch_time(3)[http://developer.apple.com/Mac/library/documentation/Darwin/Reference/ManPages/man3/dispatch_time.3.html]
*/
- rb_define_const(mDispatch, "TIME_NOW", ULL2NUM(DISPATCH_TIME_NOW));
- rb_define_const(mDispatch, "TIME_FOREVER", ULL2NUM(DISPATCH_TIME_FOREVER));
+ const_time_now = ULL2NUM(DISPATCH_TIME_NOW);
+ const_time_forever = ULL2NUM(DISPATCH_TIME_FOREVER);
+ rb_define_const(mDispatch, "TIME_NOW", const_time_now);
+ rb_define_const(mDispatch, "TIME_FOREVER", const_time_forever);
/* Constants for future reference */
selClose = sel_registerName("close");
assert(selClose != NULL);
-}
+}
View
7 spec/macruby/core/gcd/source_spec.rb
@@ -416,6 +416,13 @@
@count.should == repeats
@count.should == ((t1-t0).to_f / @interval).to_i
end
+
+ it "should not repeat with TIME_FOREVER" do
+ @count = 0
+ @src = Dispatch::Source.timer(0, Dispatch::TIME_FOREVER, 0, @q) { @count += 1 }
+ sleep 0.1
+ @count.should == 1
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.