Dev Helpers
← Back

Flush asynchronous cleanup before returning

Flush asynchronous cleanup before returning in JavaScript.

Open this example in the interactive library

Source code

async function work() {
  try {
    return "result";
  } finally {
    await Promise.resolve();
    console.log("cleanup");
  }
}
console.log(await work());

Sample output

cleanup
result