Skip to content

Instantly share code, notes, and snippets.

@marta-krzyk-dev
Last active July 3, 2020 03:44
Show Gist options
  • Save marta-krzyk-dev/70a2d1c4f7e43662d132d95d42595aa1 to your computer and use it in GitHub Desktop.
Save marta-krzyk-dev/70a2d1c4f7e43662d132d95d42595aa1 to your computer and use it in GitHub Desktop.
Simplest Promise in JS
//Based on: https://www.youtube.com/watch?v=s6SH72uAn3Q
let promiseToCleanRoom = new Promise(function(resolve, reject) {
//cleaning the room
let isClean = false;
if (isClean)
resolve('Clean');
else
reject('Dirty');
});
promiseToCleanRoom.then(function(fromResolve){
console.log('the room is ' + fromResolve);
}).catch(function(fromReject){
console.log('the room is ' + fromReject);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment