Settle
settle awaits a promise and hands you its error instead of throwing it — so you can handle a failure with an early return rather than wrapping the call in a try/catch block.
Use await without try/catch
await makes promises look nice and synchronous, but it forces you to use try/catch blocks to catch errors. That looks ugly.
This makes it pretty with good ol’ callback-style values.
let usertry { user = await getUser(id)} catch (error) { // Do something with error}const [user, error] = await settle(getUser(id))if (error) { // Do something with error}Await multiple promises together like Promise.all
Pass an array of promises and settle awaits them together.
Every value comes back in the order you passed them, just like Promise.all, with the error at the end.
let userlet poststry { [user, posts] = await Promise.all([getUser(id), getPosts(id)])} catch (error) { // Do something with error}const [user, posts, error] = await settle([getUser(id), getPosts(id)])if (error) { // Do something with error}