promise-limit | limits calls to functions that return promises | Reactive Programming library
kandi X-RAY | promise-limit Summary
kandi X-RAY | promise-limit Summary
promise-limit [Build Status] ===. Limit outstanding calls to promise returning functions, or a semaphore for promises. You might want to do this to reduce load on external services, or reduce memory usage when processing large batches of jobs.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- creates a new scheduler
promise-limit Key Features
promise-limit Examples and Code Snippets
Community Discussions
Trending Discussions on promise-limit
QUESTION
I have a large number of images that I want to download. I'm using the request-promise
package to download the images from their URL(s). Since there were a large number of images, the server was getting overloaded and the downloads would hang or get corrupted, so I decided to use the promise-limit
library to set the concurrency limit. Here is my code :
ANSWER
Answered 2021-Jan-16 at 18:53Your function downloadRequest()
does not return a promise. It must return a promise that is tied to the asynchronous operation in contains such that the promise is resolved when that asynchronous operation is complete or rejected when that asynchronous operation has an error. Only when it does that can the limit()
package properly do its job.
Since you're using a stream and piping it in downloadRequest()
, you will have to manually construct a promise and then monitor the various events in the stream to know when it's done or has an error so you can resolve or reject that promise.
Here's an idea how to make downloadRequest()
properly return a promise:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install promise-limit
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page