JSFiddle - React, Tailwind, and code Playground

by extempl

JavaScript

function _resolve(i) {
  return function () {
    console.log(i, 'resolve')
  }
}

function _reject(i) {
  return function (rejectI) {
    console.log(i, 'reject')
    return Promise.reject(rejectI) // throwing reject through all next `then`s, otherwise next `then` will call `resolve`
  }
}

a = new Promise(function(resolve, reject) {
  console.log(1, 'resolve')
  resolve(true)
})

a.then(_resolve(2), _reject(2))
  .then(function() {
  	_resolve(3)()
    return Promise.reject(3) // reject in certain resolve
  }, _reject(3))
  .then(_resolve(4), _reject(4))
  .then(_resolve(5), _reject(5))
	.catch(function (rejectI) {
  	console.log('rejected on', rejectI)
  })