Skip to main content

Task

Enum Task 

Source
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.

Fields

§id: i32

The id setTimeout returned, for clearTimeout.

§callback: Value

What to call when it fires.

§due_at: Instant

When it becomes runnable, as a monotonic instant.

Trait Implementations§

Source§

impl Trace for Task

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Report every Gc owned by self to tracer.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Task

§

impl !Send for Task

§

impl !Sync for Task

§

impl !UnwindSafe for Task

§

impl Forget for Task

§

impl Freeze for Task
where *const GcBox<JsString> is !null: Freeze, *const GcBox<JsObject> is !null: Freeze, *const GcBox<JsSymbol> is !null: Freeze, *const GcBox<BigInt> is !null: Freeze,

§

impl Move for Task

§

impl Unpin for Task
where *const GcBox<JsString> is !null: Unpin, *const GcBox<JsObject> is !null: Unpin, *const GcBox<JsSymbol> is !null: Unpin, *const GcBox<BigInt> is !null: Unpin,

§

impl UnsafeUnpin for Task
where *const GcBox<JsString> is !null: UnsafeUnpin, *const GcBox<JsObject> is !null: UnsafeUnpin, *const GcBox<JsSymbol> is !null: UnsafeUnpin, *const GcBox<BigInt> is !null: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.