The only benefit of async
is as a visual marker that the function will (always) return a promise, and you don't even have to scan the function body for the return
statement. It might be useful for consistency if you have a row of async function
s.
Apart from that: there's absolutely zero benefit from it. It's as good as wrapping the return value in an additional Promise.resolve()
call. If your function body only consists of a return
statement with a promise (either a new Promise
or another function call), I recommend not to use async
.
In general, if your function body does not contain an await
expression, you probably don't need the async
keyword either. The exception from the rule is when you want to make sure that the function always returns a promise, even if there's an exception raised in the code which should lead to a promise rejection.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…