Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Asynchronous code #62

@qwenger

Description

@qwenger

I have trouble getting asynchronous code (async/await, Promise's) to work. I tried several approaches without much luck:

ctx = quickjs.Context()

ctx.add_callable("print", print)

ctx.eval("""
async function a() {
    print(1 + await 1);
}

a();
""")
ctx.eval("""
Promise.resolve(3).then(
    r => print(r)
);
""")
f = quickjs.Function("f", """
var b = {};

async function a() {
    b.x = 1 + await 1;
}

a()

function f() {
    while (!b.x) {}
    return b.x;
}
""")

f()

The two first codes execute without printing anything. The third code hangs due to non-terminating busy waiting.

Note: the codes work correctly in qjs (quickjs' interactive prompt), of course replacing print with console.log in the first two examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions