40 ms·
if you await for an async to return then why do you use async in the first place?
by pestatije 2y ago
if you await for an async to return then why do you use async in the first place?
- mdc2161 2y agoIf the inner function is async, then its callers need to be async as well (see https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...). Important to note that unless the inner function throws an exception, the two versions are essentially identical, even sharing (if using typescript) a return type definition of `Promise<ReturnType<InnerFunction>>`. That's because `await` flattens nested promises, so both `Awaited<Promise<T>>` and `Awaited<Promise<Promise<Promise<T>>>>` resolve to `T`.