summaryrefslogtreecommitdiff
path: root/lib/api.js
diff options
context:
space:
mode:
authorJulien Dessaux2023-06-11 23:35:50 +0200
committerJulien Dessaux2023-06-11 23:35:50 +0200
commite18c5b1fdfb0f62c0d8dd8fd474d2ff3ed1acd5c (patch)
tree786ded7bcdf630299cd82473bbfff98a755f9977 /lib/api.js
parentReworked the network code to improve sending rate management (diff)
downloadspacetraders-e18c5b1fdfb0f62c0d8dd8fd474d2ff3ed1acd5c.tar.gz
spacetraders-e18c5b1fdfb0f62c0d8dd8fd474d2ff3ed1acd5c.tar.bz2
spacetraders-e18c5b1fdfb0f62c0d8dd8fd474d2ff3ed1acd5c.zip
Take requests time in consideration for rate limiting calculations
Diffstat (limited to 'lib/api.js')
-rw-r--r--lib/api.js7
1 files changed, 6 insertions, 1 deletions
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;