promise allsettled polyfill node

Solutions on MaxInterview for promise allsettled polyfill node by the best coders in the world

showing results for - "promise allsettled polyfill node"
Emelie
28 Feb 2020
1Promise.myAll = function (promises) {
2  var count = promises.length
3  var result = new Array(count).fill(false)
4 	return new Promise((resolve, reject) => {
5    	var checkIfDone = () => {
6    		if (--count === 0) resolve(result)
7    	}
8    promises.forEach((promise, index) => {
9    	promise.then( (x) => {
10      	result[index] = x
11      }, reject).then(checkIfDone)
12    })
13 })
14}
Mohamed
20 May 2019
1Promise.allSettled = function (promises) {
2  let mappedPromises = promises.map((p) => {
3    return p      
4      .then((value) => {        
5        return {          
6          status: 'fulfilled',         
7          value,        
8        };      
9      })      
10      .catch((reason) => {        
11        return {          
12          status: 'rejected',        
13          reason,        
14        };      
15      });  
16    });  
17  return Promise.all(mappedPromises);};