So, the one case where it doesn't is if you have a function marked async that doesn't have an await in it.
async function foo() {
return 4;
}
That's just returning a value, so v8 would still need to wrap that in a promise.
But when you have an await, what are you awaiting? Either the function you're awaiting is directly returning a promise, or somewhere down the line some function is directly returning a promise, meaning as it walks back up the line of async functions all the times it wrapped it in another promise were unnecessary.
Let's say you design an interface for some data fetching util, but you ship different implementations to different clients/platforms, and the appropriate implementation is DI'd at runtime.
Well consider the method that actually performs the request. It'll be async. But in some cases (namely tests in this example) you might want to return some stubbed data for your test instead. So in your test implementation of the util that "async" method just returns your dummy JSON and you don't need to wrap it in a promise.
Oh that's fair. There have been times where I have an async function return a cached response instead of fetching a new one, so that's another use case that I've written. But really I'd guess 99% of async functions are actually awaiting or returning a Promise directly.
2
u/blood_bender Apr 24 '19
So, the one case where it doesn't is if you have a function marked async that doesn't have an await in it.
That's just returning a value, so v8 would still need to wrap that in a promise.
But when you have an
await, what are you awaiting? Either the function you're awaiting is directly returning a promise, or somewhere down the line some function is directly returning a promise, meaning as it walks back up the line ofasyncfunctions all the times it wrapped it in another promise were unnecessary.