xavi- / node-simple-rate-limiter

A simple way to rate limit how often a function is executed.
76 stars 10 forks source link

Usage of request-promise #8

Closed KobeGlobal closed 1 year ago

KobeGlobal commented 7 years ago

Does the simple-rate-limiter work with request-promise?

I'm currently getting this error when using it with request-promise

TypeError: requestPromise(...).catch is not a function at promiseRetry.retries (C:\project\node_modules\request-promise-retry\index.js:18:27) at C:\project\node_modules\promise-retry\index.js:29:24 at

xavi- commented 1 year ago

Added support for promises in 0.5.0. Example usage:

const promiser = num => new Promise(resolve => resolve(num * 2));
const limited = limit.promise(promiser).to(5).per(1000);

const numbers = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
const doubled = await Promise.all(numbers.map(num => limited(num)));

assert.deepEqual(doubled, [ 2, 4, 6, 8, 10, 12, 14, 16, 18 ]);