5

If I use async/await function in a nested function call, I think the callers of that async/await functions should have async/await prefix.

For example, in this situation:

function a() {
  b();
}
function b() {
  c();
}
function c() {
  d();
}

...

function y() {
  z();
}

If z was async function, those functions should be:

async function a() {
  await b();
}
async function b() {
  await c();
}
async function c() {
  await d();
}

...

async function y() {
  await z();
}

When/How is it appropriate to stop the chaining of async/await?

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
yakkisyou
  • 510
  • 7
  • 14

1 Answers1

2

async function is just syntactic sugar for promises. It's a function that returns a promise and should be treated like one.

At some point there should have either:

a().catch(...)

Or async IIFE:

(async () => {
  try {
    await a();
  } catch (e) { ... }
})();
Estus Flask
  • 206,104
  • 70
  • 425
  • 565