Search code examples
node.jsp-limit

pLimit giving me a list of undefined promises


        const maxParallelRequests = 1;
        const limit = pLimit(maxParallelRequests);

        // Use the map method to create an array of promises for each call to GetData
        const promises = items.map(item => {
            limit(() => this.getData(item))
        });

When I log promises I get an array of 60 undefined items.

What am I doing wrong here?

item is defined inside the map function.


Solution

  • I had to add return in the map:

            // Use the map method to create an array of promises for each call to GetData
            const promises = items.map(item => {
                return limit(() => this.getData(item))
            });