Add timer.again method

pull/5370/head
Ryan Dahl 2010-03-11 12:38:42 -08:00
parent 03f2bfe51f
commit 9b67962a44
2 changed files with 14 additions and 0 deletions

View 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();
}

View 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);