From e18c5b1fdfb0f62c0d8dd8fd474d2ff3ed1acd5c Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sun, 11 Jun 2023 23:35:50 +0200 Subject: Take requests time in consideration for rate limiting calculations --- lib/api.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/api.js') diff --git a/lib/api.js b/lib/api.js index 7bbd156..9f9fc3e 100644 --- a/lib/api.js +++ b/lib/api.js @@ -30,8 +30,13 @@ async function queue_processor() { await new Promise(resolve => bus.once('send', resolve)); busy = true; } + const before = new Date(); await send_this(queue.dequeue().element); - await sleep(400); // 333 should work, but 400 should still allow some manual requests to go through during development + const duration = new Date() - before; + console.log(before.toISOString(), new Date().toISOString(), duration); + if (duration < 400) { // 333 should work, but 400 should still allow some manual requests to go through during development + await sleep(400 - duration); + } } catch (e) { running = false; throw e; -- cgit v1.2.3