sindresorhus / p-limit

Run multiple promise-returning & async functions with limited concurrency
MIT License
1.84k stars 99 forks source link

pLimit giving me a list of undefined promises #67

Closed ralyodio closed 8 months ago

ralyodio commented 1 year ago
        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.

SleeplessByte commented 1 year ago

You're not returning the result of the limit function.

// Your code 
.map((..) => { ... })

// Explicit return
.map((..) => { return ... })

// Implicit return
.map((..) => ...)