Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/p-limit/index.js

    r59329aa re29cc2e  
    11'use strict';
    2 const Queue = require('yocto-queue');
     2const pTry = require('p-try');
    33
    44const pLimit = concurrency => {
    55        if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
    6                 throw new TypeError('Expected `concurrency` to be a number from 1 and up');
     6                return Promise.reject(new TypeError('Expected `concurrency` to be a number from 1 and up'));
    77        }
    88
    9         const queue = new Queue();
     9        const queue = [];
    1010        let activeCount = 0;
    1111
     
    1313                activeCount--;
    1414
    15                 if (queue.size > 0) {
    16                         queue.dequeue()();
     15                if (queue.length > 0) {
     16                        queue.shift()();
    1717                }
    1818        };
    1919
    20         const run = async (fn, resolve, ...args) => {
     20        const run = (fn, resolve, ...args) => {
    2121                activeCount++;
    2222
    23                 const result = (async () => fn(...args))();
     23                const result = pTry(fn, ...args);
    2424
    2525                resolve(result);
    2626
    27                 try {
    28                         await result;
    29                 } catch {}
    30 
    31                 next();
     27                result.then(next, next);
    3228        };
    3329
    3430        const enqueue = (fn, resolve, ...args) => {
    35                 queue.enqueue(run.bind(null, fn, resolve, ...args));
    36 
    37                 (async () => {
    38                         // This function needs to wait until the next microtask before comparing
    39                         // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
    40                         // when the run function is dequeued and called. The comparison in the if-statement
    41                         // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
    42                         await Promise.resolve();
    43 
    44                         if (activeCount < concurrency && queue.size > 0) {
    45                                 queue.dequeue()();
    46                         }
    47                 })();
     31                if (activeCount < concurrency) {
     32                        run(fn, resolve, ...args);
     33                } else {
     34                        queue.push(run.bind(null, fn, resolve, ...args));
     35                }
    4836        };
    4937
    50         const generator = (fn, ...args) => new Promise(resolve => {
    51                 enqueue(fn, resolve, ...args);
    52         });
    53 
     38        const generator = (fn, ...args) => new Promise(resolve => enqueue(fn, resolve, ...args));
    5439        Object.defineProperties(generator, {
    5540                activeCount: {
     
    5742                },
    5843                pendingCount: {
    59                         get: () => queue.size
     44                        get: () => queue.length
    6045                },
    6146                clearQueue: {
    6247                        value: () => {
    63                                 queue.clear();
     48                                queue.length = 0;
    6449                        }
    6550                }
     
    7055
    7156module.exports = pLimit;
     57module.exports.default = pLimit;
Note: See TracChangeset for help on using the changeset viewer.