Skip to content

Instantly share code, notes, and snippets.

@dhilst
Created March 13, 2018 20:56
Show Gist options
  • Select an option

  • Save dhilst/335659b6ed740e7bd54fc791bcf24fee to your computer and use it in GitHub Desktop.

Select an option

Save dhilst/335659b6ed740e7bd54fc791bcf24fee to your computer and use it in GitHub Desktop.
const foo = new Promise((resolve,reject) => {
const failed = Math.random() > 0.5;
setTimeout(data => {
if (failed) {
reject(data);
} else {
resolve(data);
}
})
});
foo.then(x => console.log("resolved"))
.catch(err => console.error("rejected"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment