pub enum Task {
Timer {
id: i32,
callback: Value,
due_at: Instant,
},
}Expand description
One macro-task: work the event loop owes the script but has not run yet.
The microtask queue (Job) is different: those run before the host regains control.
A timer is the opposite — it is explicitly “later”, and only an event loop can honour
that. Keeping it here rather than in the host is what lets run_one_turn be pure
logic: the engine decides what is due, the host decides how to wait.
The callback is a Value, so the Gc inside it keeps the function alive by
reference counting even though nothing else references it — the same rule the HostFn
documentation states from the other side (a host closure must not hold a Gc, so the
Gc lives here instead).
Variants§
Timer
A setTimeout that is due at due_at.
There is no setInterval variant because the reference has no os.setInterval at
all: quickjs-libc.c defines only setTimeout and clearTimeout, and
typeof os.setInterval is "undefined" under qjs --std. A repeat field here
would give this engine a timer the reference cannot produce, with nothing to
compare it against.