Skip to content

Commit

Permalink
add queue threshold to trackersAssigned
Browse files Browse the repository at this point in the history
  • Loading branch information
JovannMC committed Jul 25, 2024
1 parent 053dd77 commit d03604a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/mode/com.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ export default class COM extends EventEmitter {
* startConnection() helper functions
*/

const dataQueue: { data: string; port: string }[] = [];
let isOverThreshold = false;
let dataQueue: { data: string; port: string }[] = [];

async function processData(data: string, port: string) {
try {
Expand Down Expand Up @@ -252,7 +253,14 @@ async function processData(data: string, port: string) {
}

// Check if all trackers are assigned and queue if not
if (!trackersAssigned) {
if (!trackersAssigned && !isOverThreshold) {
if (dataQueue && dataQueue.length >= 100) {
isOverThreshold = true;
log(`Data queue is over threshold, assuming not all trackers have been connected.`);
dataQueue = null;
return;
}

dataQueue.push({ data, port });
log(`Trackers not assigned yet, data in queue: ${dataQueue.length}`);
}
Expand Down

0 comments on commit d03604a

Please sign in to comment.