MCPcopy Create free account
hub / github.com/buke/quickjs-go / js_std_loop_once

Function js_std_loop_once

deps/quickjs/quickjs-libc.c:4857–4888  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4855}
4856
4857int js_std_loop_once(JSContext *ctx)
4858{
4859 JSRuntime *rt = JS_GetRuntime(ctx);
4860 JSThreadState *ts = js_get_thread_state(rt);
4861 JSContext *ctx1;
4862 int err, min_delay;
4863
4864 /* execute all pending jobs */
4865 for(;;) {
4866 err = JS_ExecutePendingJob(rt, &ctx1);
4867 if (err < 0)
4868 return -2; /* error */
4869 if (err == 0)
4870 break;
4871 }
4872
4873 /* run at most one expired timer */
4874 if (js_os_run_timers(rt, ctx, ts, &min_delay) < 0)
4875 return -2; /* error in timer callback */
4876
4877 /* check if more work is pending */
4878 if (JS_IsJobPending(rt))
4879 return 0; /* more microtasks pending */
4880
4881 if (min_delay == 0)
4882 return 0; /* timer ready to fire immediately */
4883
4884 if (min_delay > 0)
4885 return min_delay; /* next timer delay in ms */
4886
4887 return -1; /* idle, no pending work */
4888}
4889
4890/* Wait for a promise and execute pending jobs while waiting for
4891 it. Return the promise result or JS_EXCEPTION in case of promise

Callers 1

AwaitValueFunction · 0.85

Calls 2

js_get_thread_stateFunction · 0.85
js_os_run_timersFunction · 0.85

Tested by

no test coverage detected