Promise.try
Turn any function into a Promise with Promise.try.
const doStuff = () => {
return 'stuff complete';
}
Promise.try(doStuff)
.then(result => console.log(result))
.catch(err => console.error(err))
.finally(() => console.log('process done'));const doOtherStuff = () => {
throw new Error('Uh oh!');
}
Promise.try(doOtherStuff)
.then(result => console.error(result))
.catch(err => console.error(err))
.finally(() => console.log('process done'));const doMoreStuff = () => new Promise((resolve) => {
setTimeout(() => {
resolve('stuff complete');
}, 1000);
})
Promise.try(doMoreStuff)
.then(result => console.log(result))
.catch(err => console.error(err))
.finally(() => console.log('process done'));