Quirrel4.41.0

Async runtime

The C side of async and await: installing the runtime, driving it once per frame, and settling a Future from native code.

The runtime does not run itself. sqasync::pump advances every task that waits on a Future. In a host that never calls it, async functions start and never finish. See The async runtime for where to put that call and how to shut down cleanly.

The descriptions here come from the header, which documents these functions in more detail.

SQRESULT sqasync::bind(HSQUIRRELVM v)

Install the async runtime into the VM's shared state and build the Future class.

SQInteger sqasync::pump(HSQUIRRELVM v, SQInteger maxSteps = 1024)

Drain the inbox + internal step queue.

SQBool sqasync::has_pending(HSQUIRRELVM v)

True iff the runtime has work it can drive forward on its own (queue or inbox non-empty, or a deferred unhandled-fault sweep is pending).

SQRESULT sqasync::post_on_vm_thread(HSQUIRRELVM v, VmCallback fn, void *user)

Schedule fn(user) to run on the VM thread inside the next pump().

SQRESULT sqasync::post_from_any_thread(HSQUIRRELVM v, VmCallback fn, void *user)

Thread-safe variant of post_on_vm_thread: any thread may call.

SQRESULT sqasync::future_push_class(HSQUIRRELVM v)

Push the cached Future class onto the stack.

SQRESULT sqasync::future_create(HSQUIRRELVM v, HSQOBJECT *out)

Create a fresh Future instance and write an addref'd handle into *out.

SQRESULT sqasync::future_resolve(HSQUIRRELVM v, HSQOBJECT future, HSQOBJECT value)

Settle a Future from C.

SQRESULT sqasync::future_throw(HSQUIRRELVM v, HSQOBJECT future, HSQOBJECT value)

Settles a Future from C with a thrown value, the failure counterpart of future_resolve.

SQInteger sqasync::sqasync_register(HSQUIRRELVM v)

SqModules RegFunc-shaped entry point.