leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2636.js (402B)


      1 /**
      2  * @param {Function[]} functions
      3  * @param {number} n
      4  * @return {Function}
      5  */
      6 
      7 var promisePool = async function(functions, n) {
      8     async function evaluateNext() {
      9         if (functions.length === 0) return;
     10         const fn = functions.shift();
     11         await fn();
     12         await evaluateNext();
     13     }
     14     const nPromises = Array(n).fill().map(evaluateNext);
     15     await Promise.all(nPromises);
     16 };