Skip to content

Cannot await inside callback #22

@timstableford

Description

@timstableford
local res = sleep(1):next(function ()
    sleep(10):await()
    return 15
end)
print("res", res:await())

Returns

Error: Lua Error(ErrorRun/2): cannot resume dead coroutine
    at Thread.assertOk (/home/tstableford/projects/wasmoon/dist/index.js:409:23)
    at Thread.<anonymous> (/home/tstableford/projects/wasmoon/dist/index.js:142:22)
    at Generator.throw (<anonymous>)
    at rejected (/home/tstableford/projects/wasmoon/dist/index.js:26:69)

This makes sense because aren't async and aren't threads. That means they attempt to run within the parent thread. If they did run in a child thread then it would be possible to make jsFunc's async but then it would get a bit mad with async everywhere.

Maybe there's a good solution and maybe not, if there's not though it should be documented.

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