Skip to content

Commit 23492f2

Browse files
committed
Readme examples so they compile
1 parent 3882bf9 commit 23492f2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/test/java/ReadmeExamples.java

+26
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.dataloader.fixtures.UserManager;
1313
import org.dataloader.registries.DispatchPredicate;
1414
import org.dataloader.registries.ScheduledDataLoaderRegistry;
15+
import org.dataloader.scheduler.BatchLoaderScheduler;
1516
import org.dataloader.stats.Statistics;
1617
import org.dataloader.stats.ThreadLocalStatisticsCollector;
1718

@@ -23,6 +24,7 @@
2324
import java.util.Set;
2425
import java.util.concurrent.CompletableFuture;
2526
import java.util.concurrent.CompletionStage;
27+
import java.util.function.Function;
2628
import java.util.stream.Collectors;
2729

2830
import static java.lang.String.format;
@@ -278,6 +280,30 @@ private void statsConfigExample() {
278280
DataLoader<String, User> userDataLoader = DataLoaderFactory.newDataLoader(userBatchLoader, options);
279281
}
280282

283+
private void snooze(int i) {
284+
}
285+
286+
private void BatchLoaderSchedulerExample() {
287+
new BatchLoaderScheduler() {
288+
289+
@Override
290+
public <K, V> CompletionStage<List<V>> scheduleBatchLoader(ScheduledBatchLoaderCall<V> scheduledCall, List<K> keys, BatchLoaderEnvironment environment) {
291+
return CompletableFuture.supplyAsync(() -> {
292+
snooze(10);
293+
return scheduledCall.invoke();
294+
}).thenCompose(Function.identity());
295+
}
296+
297+
@Override
298+
public <K, V> CompletionStage<Map<K, V>> scheduleMappedBatchLoader(ScheduledMappedBatchLoaderCall<K, V> scheduledCall, List<K> keys, BatchLoaderEnvironment environment) {
299+
return CompletableFuture.supplyAsync(() -> {
300+
snooze(10);
301+
return scheduledCall.invoke();
302+
}).thenCompose(Function.identity());
303+
}
304+
};
305+
}
306+
281307
private void ScheduledDispatche() {
282308
DispatchPredicate depthOrTimePredicate = DispatchPredicate.dispatchIfDepthGreaterThan(10)
283309
.or(DispatchPredicate.dispatchIfLongerThan(Duration.ofMillis(200)));

0 commit comments

Comments
 (0)