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