#include <stdlib.h>
#include <string.h>
#include "uv.h"
#include "scheduler.h"
#include "vm.h"
#include "wren.h"
static void timerCloseCallback(uv_handle_t* handle)
{
free(handle);
}
static void timerCallback(uv_timer_t* handle)
{
WrenHandle* fiber = (WrenHandle*)handle->data;
uv_close((uv_handle_t*)handle, timerCloseCallback);
schedulerResume(fiber, false);
}
void timerStartTimer(WrenVM* vm)
{
int milliseconds = (int)wrenGetSlotDouble(vm, 1);
WrenHandle* fiber = wrenGetSlotHandle(vm, 2);
uv_timer_t* handle = (uv_timer_t*)malloc(sizeof(uv_timer_t));
handle->data = fiber;
uv_timer_init(getLoop(), handle);
uv_timer_start(handle, timerCallback, milliseconds, 0);
}