-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathgetBigList.js
More file actions
22 lines (19 loc) · 691 Bytes
/
getBigList.js
File metadata and controls
22 lines (19 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Get a specific chunk with simulated delay (for true streaming)
export async function getChunk(
chunkIndex,
totalItems = 10_000,
chunkSize = 100
) {
// Simulate progressive data fetching - each chunk takes incrementally longer
// This creates a waterfall effect where chunks appear one after another
const delay = chunkIndex * 100; // 0ms, 100ms, 200ms, 300ms, etc.
if (delay > 0) {
await new Promise((resolve) => setTimeout(resolve, delay));
}
const startIndex = chunkIndex * chunkSize;
const endIndex = Math.min(startIndex + chunkSize, totalItems);
return Array.from(
{ length: endIndex - startIndex },
(_, i) => `Item #${startIndex + i + 1}`
);
}