Created
March 15, 2012 17:27
-
-
Save piscisaureus/2045459 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T> | |
class UvHandle { | |
T handle_; | |
public: | |
T* handle() { return &handle_; } | |
protected: | |
static void OnClose(); | |
static Value* Close(uint32_t argc, Arguments& argv); | |
}; | |
template <typename T> | |
void UvHandle<T>::OnClose() { | |
onClose->Call(0, NULL); | |
onClose.Unwrap(); | |
Unref(); | |
} | |
template <typename T> | |
Value* UvHandle<T>::Close(uint32_t argc, Arguments& argv) { | |
if (argc > 1 && argv[1]->Is<Function>()) { | |
onClose.Wrap(argv[1]->As<Function>()); | |
} | |
uv_close((uv_handle_t*) handle(), luv_on_close); | |
Ref(); | |
return Nil::New(); | |
} | |
class UvTimer | |
: public UvHandle<uv_timer_t> { | |
public: | |
static void init(Object* uv) { | |
Object* handle = Object::New(); | |
uv->Set("Handle", handle); | |
handle->Set("close", Function::New(Close)); | |
} | |
}; | |
class UvPipe | |
: public UvHandle<uv_timer_t> { | |
static void init(Object* uv) { | |
Object* handle = Object::New(); | |
uv->Set("Handle", handle); | |
handle->Set("close", Function::New(Close)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment