Mercurial
comparison third_party/libuv/docs/code/ref-timer/main.c @ 173:827c6ac504cd hg-web
Merged in default here.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 19 Jan 2026 18:59:10 -0800 |
| parents | 948de3f54cea |
| children |
comparison
equal
deleted
inserted
replaced
| 151:c033667da5f9 | 173:827c6ac504cd |
|---|---|
| 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 | |
| 9 void gc(uv_timer_t *handle) { | |
| 10 fprintf(stderr, "Freeing unused objects\n"); | |
| 11 } | |
| 12 | |
| 13 void fake_job(uv_timer_t *handle) { | |
| 14 fprintf(stdout, "Fake job done\n"); | |
| 15 } | |
| 16 | |
| 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 } |