Skip to content

async/await doesn't throw exception when reject() is called #9595

@mersadk

Description

@mersadk

TypeScript Version: 1.8.10
Tested with node v6.1.0

I have an async function that returns a Promise. If I call resolve() everything works file. If I call reject(), await will not throw any exception and program will just hang.

I used example from this blog post and it works as described (https://blogs.msdn.microsoft.com/typescript/2015/11/03/what-about-asyncawait/). If you change it to call reject() insted of resolve(), nothing will happen and a program will hang (code below).

async function main() {
 await ping();
 process.exit();
}

async function ping() {
 for (var i = 0; i < 10; i++) {
  await delay(300);
  console.log("ping");
 }
}

function delay(ms: number) {
    return new Promise((resolve, reject) => setTimeout(() => reject("This doesn't work!"), ms));
}

main();

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions