void event_cycle_once() { bool pstate = mainloop()->running; mainloop()->running = false; queue_process_events(eventq(), TIMEOUT); queue_process_events(drawq(), TIMEOUT); uv_run(eventloop(), UV_RUN_NOWAIT); uv_run(eventloop(), UV_RUN_ONCE); mainloop()->running = pstate; }
void loop_poll_events(Loop *loop, int ms) { if (loop->recursive++) { abort(); // Should not re-enter uv_run } uv_run_mode mode = UV_RUN_ONCE; if (ms > 0) { // Use a repeating timeout of ms milliseconds to make sure // we do not block indefinitely for I/O. uv_timer_start(&loop->poll_timer, timer_cb, (uint64_t)ms, (uint64_t)ms); } else if (ms == 0) { // For ms == 0, we need to do a non-blocking event poll by // setting the run mode to UV_RUN_NOWAIT. mode = UV_RUN_NOWAIT; } uv_run(&loop->uv, mode); if (ms > 0) { uv_timer_stop(&loop->poll_timer); } loop->recursive--; // Can re-enter uv_run now queue_process_events(loop->fast_events); }
static void prepare_events(uv_prepare_t *handle) { log_msg("", "--event--"); if (mainloop()->running) return; mainloop()->running = true; while (1) { queue_process_events(eventq(), TIMEOUT); queue_process_events(drawq(), TIMEOUT); if (!mainloop_busy()) { uv_prepare_stop(handle); break; } else { uv_run(eventloop(), UV_RUN_NOWAIT); } } mainloop()->running = false; }