-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.dart
37 lines (29 loc) · 1.03 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import 'package:chunk/chunk.dart';
import 'package:example/data.dart';
void main(List<String> arguments) async {
final chunker = Chunker<String, String>(
cursorSelector: (v) => v,
dataChunker: (cursor, limit) async {
final isFirstRun = cursor == null;
final data = isFirstRun
? states.take(limit)
: states
.skipWhile((value) => value != cursor)
.skip(1) // Start after the previous cursor
.take(limit);
return data.toList();
},
);
/// Async loop over the data until we're at the end.
startPaginationLoop(Chunk<String, String> chunk) async {
final nextChunk = await chunker.getNext(chunk);
print(nextChunk);
if (nextChunk.status == ChunkStatus.nextAvailable) {
await startPaginationLoop(nextChunk);
}
}
print("### Non Divisible By Limit Loop");
await startPaginationLoop(Chunk(limit: 8));
print("### Divisible By Limit Loop (extra chunk required to know we're done");
await startPaginationLoop(Chunk(limit: 10));
}