Answers for "promise.all polyfill"

0

promise.all polyfill

Promise.myAll = function (promises) {
  var count = promises.length
  var result = new Array(count).fill(false)
 	return new Promise((resolve, reject) => {
    	var checkIfDone = () => {
    		if (--count === 0) resolve(result)
    	}
    promises.forEach((promise, index) => {
    	promise.then( (x) => {
      	result[index] = x
      }, reject).then(checkIfDone)
    })
 })
}
Posted by: Guest on June-17-2021
0

promise.allsettled polyfill node

Promise.allSettled = function (promises) {
  let mappedPromises = promises.map((p) => {
    return p      
      .then((value) => {        
        return {          
          status: 'fulfilled',         
          value,        
        };      
      })      
      .catch((reason) => {        
        return {          
          status: 'rejected',        
          reason,        
        };      
      });  
    });  
  return Promise.all(mappedPromises);};
Posted by: Guest on April-28-2021

Code answers related to "promise.all polyfill"

Code answers related to "Javascript"

Browse Popular Code Answers by Language