@@ -478,6 +478,33 @@ and there are also gains to this different mode of operation:
478
478
However, with batch execution control comes responsibility! If you forget to make the call to ` dispatch() ` then the futures
479
479
in the load request queue will never be batched, and thus _ will never complete_ ! So be careful when crafting your loader designs.
480
480
481
+ ## Scheduled Dispatching
482
+
483
+ ` ScheduledDataLoaderRegistry ` is a registry that allows for dispatching to be done on a schedule. It contains a
484
+ predicate that is evaluated (per data loader contained within) when ` dispatchAll ` is invoked.
485
+
486
+ If that predicate is true, it will make a ` dispatch ` call on the data loader, otherwise is will schedule as task to
487
+ perform that check again. Once a predicate evaluated to true, it will not reschedule and another call to
488
+ ` dispatchAll ` is required to be made.
489
+
490
+ This allows you to do things like "dispatch ONLY if the queue depth is > 10 deep or more than 200 millis have passed
491
+ since it was last dispatched".
492
+
493
+ ``` java
494
+
495
+ DispatchPredicate depthOrTimePredicate = DispatchPredicate
496
+ .dispatchIfDepthGreaterThan(10 )
497
+ .or(DispatchPredicate . dispatchIfLongerThan(Duration . ofMillis(200 )));
498
+
499
+ ScheduledDataLoaderRegistry registry = ScheduledDataLoaderRegistry . newScheduledRegistry()
500
+ .dispatchPredicate(depthOrTimePredicate)
501
+ .schedule(Duration . ofMillis(10 ))
502
+ .register(" users" ,userDataLoader)
503
+ .build();
504
+ ```
505
+
506
+ The above acts as a kind of minimum batch depth, with a time overload. It won't dispatch if the loader depth is less
507
+ than or equal to 10 but if 200ms pass it will dispatch.
481
508
482
509
## Let's get started!
483
510
0 commit comments