Hard
This question is a daily question and will count towards your daily streak.
While optimizing a web application's performance, you need to implement request batching. What will be logged after processing these requests?
1class RequestBatcher {2 #queue = [];3 #processing = false;4 #batchSize;5 #processDelay;67 constructor(batchSize = 3, processDelay = 100) {8 this.#batchSize = batchSize;9 this.#processDelay = processDelay;10 }1112 async addRequest(id) {13 this.#queue.push(id);14 if (!this.#processing) {15 this.#processing = true;16 await this.#processBatch();17 }18 }1920 async #processBatch() {21 while (this.#queue.length > 0) {22 const batch = this.#queue.splice(0, this.#batchSize);23 console.log('Processing batch:', batch);24 await new Promise(resolve => setTimeout(resolve, this.#processDelay));25 }26 this.#processing = false;27 }28}2930const batcher = new RequestBatcher(2, 100);3132// Simulate incoming requests33(async () => {34 await batcher.addRequest('A');35 await batcher.addRequest('B');36 await batcher.addRequest('C');37 await batcher.addRequest('D');38})();