Start a promise chain
$ npm install p-try
const pTry = require('p-try');
pTry(() => {
return synchronousFunctionThatMightThrow();
}).then(value => {
console.log(value);
}).catch(error => {
console.error(error);
});
Returns a Promise
resolved with the value of calling fn(...args)
. If the function throws an error, the returned Promise
will be rejected with that error.
Support for passing arguments on to the fn
is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a lot of functions.
Promise#finally()
ponyfill - Invoked when the promise is settled regardless of outcomeMIT © Sindre Sorhus
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.