Add timer.again method
authorRyan Dahl <ry@tinyclouds.org>
Thu, 11 Mar 2010 20:38:42 +0000 (12:38 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 11 Mar 2010 20:38:42 +0000 (12:38 -0800)
src/node_timer.cc
src/node_timer.h

index 1fa470a..b1b6d35 100644 (file)
@@ -27,6 +27,7 @@ Timer::Initialize (Handle<Object> target)
 
   NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", Timer::Start);
   NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", Timer::Stop);
+  NODE_SET_PROTOTYPE_METHOD(constructor_template, "again", Timer::Again);
 
   constructor_template->InstanceTemplate()->SetAccessor(repeat_symbol,
       RepeatGetter, RepeatSetter);
@@ -140,3 +141,15 @@ void Timer::Stop () {
     Unref();
   }
 }
+
+
+Handle<Value> Timer::Again(const Arguments& args) {
+  HandleScope scope;
+  Timer *timer = ObjectWrap::Unwrap<Timer>(args.Holder());
+
+  ev_tstamp repeat = NODE_V8_UNIXTIME(args[0]);
+  if (repeat > 0) timer->watcher_.repeat = repeat;
+  ev_timer_again(EV_DEFAULT_UC_ &timer->watcher_);
+
+  return Undefined();
+}
index 0472fdb..fdf2a23 100644 (file)
@@ -21,6 +21,7 @@ class Timer : ObjectWrap {
   static v8::Handle<v8::Value> New (const v8::Arguments& args);
   static v8::Handle<v8::Value> Start (const v8::Arguments& args);
   static v8::Handle<v8::Value> Stop (const v8::Arguments& args);
+  static v8::Handle<v8::Value> Again (const v8::Arguments& args);
   static v8::Handle<v8::Value> RepeatGetter (v8::Local<v8::String> property, const v8::AccessorInfo& info);
   static void RepeatSetter (v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info);