main.c 607 B

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