Problem
Build an Analytics module that batches JSON blobs and sends them via an injected send(batch) API when the batch reaches batchSize OR idleDuration ms pass since the last add. Follow-ups: maxRetries, and persisting the queue to localStorage/IndexedDB until a successful send.
const sampleSend = async (batch) =>
new Promise((resolve, reject) => {
setTimeout(() => {
console.log("Processing batch", batch.map((b) => b.a));
Math.random() < 0.2 ? reject("Error in sending batch") : resolve("Success");
}, 2000);
});