xref: /libuv/docs/code/ref-timer/main.c (revision d59d6e6f)
1 #include <stdio.h>
2 
3 #include <uv.h>
4 
5 uv_loop_t *loop;
6 uv_timer_t gc_req;
7 uv_timer_t fake_job_req;
8 
gc(uv_timer_t * handle)9 void gc(uv_timer_t *handle) {
10     fprintf(stderr, "Freeing unused objects\n");
11 }
12 
fake_job(uv_timer_t * handle)13 void fake_job(uv_timer_t *handle) {
14     fprintf(stdout, "Fake job done\n");
15 }
16 
main()17 int 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