Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

if you await for an async to return then why do you use async in the first place?


If 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-...).

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`.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: