diff options
author | Julien Dessaux | 2023-06-11 23:35:50 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-06-11 23:35:50 +0200 |
commit | e18c5b1fdfb0f62c0d8dd8fd474d2ff3ed1acd5c (patch) | |
tree | 786ded7bcdf630299cd82473bbfff98a755f9977 /lib | |
parent | Reworked the network code to improve sending rate management (diff) | |
download | spacetraders-e18c5b1fdfb0f62c0d8dd8fd474d2ff3ed1acd5c.tar.gz spacetraders-e18c5b1fdfb0f62c0d8dd8fd474d2ff3ed1acd5c.tar.bz2 spacetraders-e18c5b1fdfb0f62c0d8dd8fd474d2ff3ed1acd5c.zip |
Take requests time in consideration for rate limiting calculations
Diffstat (limited to '')
-rw-r--r-- | lib/api.js | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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; |