Skip to content

Instantly share code, notes, and snippets.

@georgeck
Created July 6, 2019 02:28
Show Gist options
  • Save georgeck/ff89ce7fc78b64fd1c666e9d3230fd73 to your computer and use it in GitHub Desktop.
Save georgeck/ff89ce7fc78b64fd1c666e9d3230fd73 to your computer and use it in GitHub Desktop.
Javascript promise example
// Creating a promise
let promise = new Promise (
(resolve, reject) => {
// Some function that takes time - in this case, retuen afer 1 sec
setTimeout( () => {
if ( Math.random() > .5) {
resolve('😀');
} else {
reject('😡');
}
}, 1000);
}
);
// Settling a promise
promise.then(
success => console.log('success', success),
error => console.log('Error', error)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment