Promise in Javascript

let promiseToFixSomething = new Promise(function(resolve, reject) {
  //Learning
  let isFixed = false;

  if (isFixed ) {
    resolve('Fixed!!');
  } else {
    reject('Nah');
  }
});

promiseToFixSomething.then(function(fromResolve) {
    console.log('Fixed?' + fromResolve);
  }).catch(function(fromReject){
    console.log('Fixed?' + fromReject);
});

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Remove duplicates from a JavaScript Array

Sending Binary Data over the Network with Json