get unstuck
This commit is contained in:
parent
0c070c5aec
commit
ffc071adbb
1 changed files with 12 additions and 6 deletions
12
site.js
12
site.js
|
@ -71,17 +71,23 @@ async function rounder(users, data, mode) {
|
||||||
let p = [];
|
let p = [];
|
||||||
let congested = [];
|
let congested = [];
|
||||||
let timeout = false;
|
let timeout = false;
|
||||||
setTimeout(function() {
|
|
||||||
|
let pr = new Promise(resolve => setTimeout(function (...ag) {
|
||||||
timeout = true;
|
timeout = true;
|
||||||
},(process.env.delay*1000) || (60*1000));
|
resolve(ag);
|
||||||
|
}, (process.env.delay * 1000) || (60 * 1000)))
|
||||||
|
|
||||||
for (let u of users) {
|
for (let u of users) {
|
||||||
if (timeout) break;
|
if (timeout) break;
|
||||||
let it = 0;
|
let it = 0;
|
||||||
while (p.length >= (process.env.maxRate || 15)) {
|
while (p.length >= (process.env.maxRate || 15)) {
|
||||||
p = p.filter(x => x != 'hi');
|
p = p.filter(x => x != 'hi');
|
||||||
|
if (timeout) {
|
||||||
|
console.warn(`Somehow, this is stuck.`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (p.length == 0) break;
|
if (p.length == 0) break;
|
||||||
let pv = await Promise.any(p);
|
let pv = await Promise.any([...p,pr]);
|
||||||
it++;
|
it++;
|
||||||
if (it > 10) {
|
if (it > 10) {
|
||||||
console.warn(`Promises got congested. Moving to another array...`)
|
console.warn(`Promises got congested. Moving to another array...`)
|
||||||
|
|
Loading…
Reference in a new issue