1#include <stdio.h>
2#include <uv.h>
3
4int64_t counter = 0;
5
6void idle_cb(uv_idle_t *handle) {
7    printf("Idle callback\n");
8    counter++;
9
10    if (counter >= 5) {
11        uv_stop(uv_default_loop());
12        printf("uv_stop() called\n");
13    }
14}
15
16void prep_cb(uv_prepare_t *handle) {
17    printf("Prep callback\n");
18}
19
20int main() {
21    uv_idle_t idler;
22    uv_prepare_t prep;
23
24    uv_idle_init(uv_default_loop(), &idler);
25    uv_idle_start(&idler, idle_cb);
26
27    uv_prepare_init(uv_default_loop(), &prep);
28    uv_prepare_start(&prep, prep_cb);
29
30    uv_run(uv_default_loop(), UV_RUN_DEFAULT);
31
32    return 0;
33}
34