Skip to content

Instantly share code, notes, and snippets.

@duggiemitchell
Last active May 10, 2017 14:48
Show Gist options
  • Select an option

  • Save duggiemitchell/49fb3c9b91491ddab858a43bad682b30 to your computer and use it in GitHub Desktop.

Select an option

Save duggiemitchell/49fb3c9b91491ddab858a43bad682b30 to your computer and use it in GitHub Desktop.
Simplest example of a promise
let promiseToClean = new Promise(function( resolve, reject) { 
  // cleaning the room 
  
  let isClean = false;
  
  if (isClean){
    resolve('Clean');
  } else {
    reject('not Clean');
  }
})

The Caller:

promiseToClean.then(function() {
    console.log('the room is clean')
}).catch(function() {
    console.log('the room is not clean')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment