Skip to content

Promise tests down #1105

@websharik

Description

@websharik

tsconfig:

{
    "compilerOptions": {
        "target": "ESNext",
        "lib": ["ESNext"],
        "module": "commonjs",
        "strict": true,
        "baseUrl": ".",
        "rootDir": "src",
        "outDir": "dist",
        "paths": {},
        "plugins": [
            {
                "transform": "mtasa-lua-utils/transformer",
                "after": false,
                "externalImports": true,
                "globalExports": false
            }
        ],
        "types": ["lua-types/5.1"],
        "forceConsistentCasingInFileNames": true,
        "noImplicitAny": true,
        "noImplicitThis": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true
    },
    "tstl": {
        "luaTarget": "5.1",
        "noImplicitSelf": true,
        "luaLibImport": "none",
        "sourceMapTraceback": false,
        "noHeader": true
    },
    "bundleEntryPoints": ["src/test.ts"]
}
  1. Just await not working
(async () => {
    print('Start')
    try {
        let text = await new Promise((resolve) => { resolve("Success text") })
        print(text)
    } catch (e) {
        print(`Somethings wrong global: ${e}`)
    }
    print('End')
})()

Result:

Start
Somethings wrong global: test\vendor\lualib_bundle.lua:538: attempt to yield across metamethod/C-call boundary
End
function __TS__Await(thing)
    return coroutine.yield(thing)
end

Expected:

Start
Success text
End

But then is working:

(async () => {
    print('Start')
    try {
        new Promise((resolve) => { resolve("Success text") })
        .then((text) => {
            print(text)
        })
    } catch (e) {
        print(`Somethings wrong global: ${e}`)
    }
    print('End')
})()

Result:

Start
Success text
End
  1. Catch after then not working
(async () => {
    print('Start')
    try {
        Promise.reject('Error text')
        .then((result) => {
            print(`Result: ${result}`)
        })
        .catch((e) => {
            print(`Somethings wrong local: ${e}`)
        })
    } catch (e) {
        print(`Somethings wrong global: ${e}`)
    }
    print('End')
})()

Result:

Start
End

Expected:

Start
Somethings wrong local: Error text
End

But without .then, .catch working:

(async () => {
    print('Start')
    try {
        Promise.reject('Error text')
        .catch((e) => {
            print(`Somethings wrong local: ${e}`)
        })
    } catch (e) {
        print(`Somethings wrong global: ${e}`)
    }
    print('End')
})()

Result:

Start
Somethings wrong local: Error text
End
  1. Global catch not working
(async () => {
    print('Start')
    try {
        await new Promise((resolve, reject) => {
            reject('Error text')
        })
    } catch (e) {
        print(`Somethings wrong global: ${e}`)
    }
    print('End')
})()

Result:

Start
End

Expected:

Start
Somethings wrong global: Error text
End

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions