xref: /third_party/libuv/docs/code/ref-timer/main.c (revision e66f31c5)
1#include <stdio.h>
2
3#include <uv.h>
4
5uv_loop_t *loop;
6uv_timer_t gc_req;
7uv_timer_t fake_job_req;
8
9void gc(uv_timer_t *handle) {
10    fprintf(stderr, "Freeing unused objects\n");
11}
12
13void fake_job(uv_timer_t *handle) {
14    fprintf(stdout, "Fake job done\n");
15}
16
17int main() {
18    loop = uv_default_loop();
19
20    uv_timer_init(loop, &gc_req);
21    uv_unref((uv_handle_t*) &gc_req);
22
23    uv_timer_start(&gc_req, gc, 0, 2000);
24
25    // could actually be a TCP download or something
26    uv_timer_init(loop, &fake_job_req);
27    uv_timer_start(&fake_job_req, fake_job, 9000, 0);
28    return uv_run(loop, UV_RUN_DEFAULT);
29}
30