1
0
forked from Mirror/wren

Properly dispose of libuv timers when we finish using them

This commit is contained in:
Rohan Singh
2015-08-13 01:54:30 -04:00
parent 0efb943173
commit cb603f44c2

View File

@ -28,11 +28,19 @@ static const char* timerLibSource =
// The Wren method to call when a timer has completed.
static WrenMethod* resumeTimer;
// Called by libuv when the timer finished closing.
static void timerCloseCallback(uv_handle_t* handle)
{
free(handle);
}
// Called by libuv when the timer has completed.
static void timerCallback(uv_timer_t* handle)
{
WrenValue* fiber = (WrenValue*)handle->data;
free(handle);
// Tell libuv that we don't need the timer anymore.
uv_close((uv_handle_t*)handle, timerCloseCallback);
// Run the fiber that was sleeping.
wrenCall(getVM(), resumeTimer, "v", fiber);