Added onboarding and exe output.
This commit is contained in:
+18
-3
@@ -1,10 +1,25 @@
|
||||
const pThrottleModule = require('p-throttle');
|
||||
const pThrottle = pThrottleModule.default || pThrottleModule;
|
||||
function sleep(milliseconds) {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
||||
}
|
||||
|
||||
function buildThrottle(maxRequestsPerMinute) {
|
||||
const limit = Math.max(1, Math.floor(maxRequestsPerMinute));
|
||||
const interval = Math.ceil(60000 / limit);
|
||||
return pThrottle({limit: 1, interval});
|
||||
let nextAvailable = 0;
|
||||
|
||||
return function throttle(fn) {
|
||||
return async function throttledFunction(...args) {
|
||||
const now = Date.now();
|
||||
const waitMs = Math.max(0, nextAvailable - now);
|
||||
nextAvailable = Math.max(nextAvailable, now) + interval;
|
||||
|
||||
if (waitMs > 0) {
|
||||
await sleep(waitMs);
|
||||
}
|
||||
|
||||
return fn(...args);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function applyRateLimitBuffer(rateLimitPerMinute) {
|
||||
|
||||
Reference in New Issue
Block a user