pumpTimers method
Advances the JavaScript event loop once.
Runs due timers and Promise jobs, then returns the delay until the next timer. A null result means that no timer is currently scheduled.
Normal run and call requests do not need this. It is intended for long-lived hosts, such as UI or service containers, that must keep timers moving while no JavaScript request is active. Backends without native deadline inspection use a bounded 500ms compatibility poll.
Implementation
Future<Duration?> pumpTimers() async {
final runtime = _runtime;
if (runtime is JsTimerRuntimeBase) {
final milliseconds = await (runtime as JsTimerRuntimeBase).pumpTimers();
return milliseconds == null ? null : Duration(milliseconds: milliseconds);
}
await runRaw(
'await new Promise((resolve) => setTimeout(resolve, 0)); return null;',
name: '<quickjs:timer-pump>',
);
return const Duration(milliseconds: 500);
}