network chunk v2

This commit is contained in:
andrei-mihnea-cerbu
2024-11-12 23:14:08 +02:00
parent 44df437425
commit fa4750ea3b
4 changed files with 53 additions and 49 deletions
+3 -9
View File
@@ -28,24 +28,18 @@ export class FileSharer {
async start(): Promise<void> {
setInterval(async () => {
if (!this.isBusy) { // Check if the queue is already being processed
this.isBusy = true; // Set busy flag to true before starting
this.log("Start successfully. Processing the queue.");
await this.processQueue(); // Process the queue at regular intervals
this.log("Queue processing completed.");
await this.processQueue();
}
}, 10000); // 10 seconds interval
}
// Method to process the queue
private async processQueue(): Promise<void> {
if (this.isBusy) {
this.log("Queue is already being processed. Skipping this interval.");
return;
}
this.isBusy = true; // Set busy flag to true before starting
while (!this.queueManager.isEmpty()) {
const task = this.queueManager.peek();
this.log('trimiti fisier');
if (task) {
this.log(`Processing task for file: ${task.path} to IP: ${task.ip}`);