Closed sean-hill closed 9 years ago
Haha. I don't even need this module. Here's my solution. 1000ms / 25 = 40ms
.
async.eachSeries(emails, function(email, nextEmail){
setTimeout(function(){
asyncEmailFunction(email);
return nextEmail();
}, 40);
});
Glad you worked out a solution. This module is most useful for dealing with unexpected bursts of activity. When you have a known number of tasks that you want to run at a known rate there are easier options like what you pasted above.
For future reference, here is how you'd approach this with RateLimter (ES6):
import { RateLimiter } from "limiter";
const emails = [...]
const limiter = new RateLimiter(1, 40); // max 1 email per 40 ms
emails.forEach(email => {
limiter.removeTokens(1, () => {
this.sendEmail(email);
});
});
Hey there
I have a list of 100k emails. I'd like to only send 25 per second. I have setup the code like this:
It works great until about 300 emails, then it just bogs down and doesn't complete them as fast.