i18n-ai-translate
Version:
Use LLMs to translate your i18n JSON to any language.
29 lines • 943 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
class RateLimiter {
lastAPICall;
delayBetweenCallsMs;
verboseLogging;
constructor(delayBetweenCallsMs, verboseLogging) {
this.lastAPICall = null;
this.delayBetweenCallsMs = delayBetweenCallsMs;
this.verboseLogging = verboseLogging;
}
apiCalled() {
this.lastAPICall = Date.now();
}
async wait() {
if (this.lastAPICall) {
const timeToWait = this.delayBetweenCallsMs - (Date.now() - this.lastAPICall);
if (timeToWait > 0) {
await (0, utils_1.delay)(timeToWait);
if (this.verboseLogging) {
console.log(`RateLimiter | Waiting ${timeToWait}ms before next API call`);
}
}
}
}
}
exports.default = RateLimiter;
//# sourceMappingURL=rate_limiter.js.map
;