You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-21Lines changed: 28 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,29 +87,29 @@ You can then use it to load values which will be `CompleteableFuture` promises t
87
87
```
88
88
89
89
or you can use it to compose future computations as follows. The key requirement is that you call
90
-
`dataloader.dispatch()` at some point in order to make the underlying calls happen to the batch loader.
91
-
In this version of data loader, this does not happen automatically. More on this later.
90
+
`dataloader.dispatch()`or its variant `dataloader.dispatchAndJoin()`at some point in order to make the underlying calls happen to the batch loader.
91
+
In this version of data loader, this does not happen automatically. More on this in [Manual dispatching](#manual-dispatching).
92
92
93
93
```java
94
-
userLoader.load(1L)
95
-
.thenAccept(user -> {
96
-
System.out.println("user = "+ user);
97
-
userLoader.load(user.getInvitedByID())
98
-
.thenAccept(invitedBy -> {
99
-
System.out.println("invitedBy = "+ invitedBy);
100
-
});
101
-
});
102
-
103
-
userLoader.load(2L)
104
-
.thenAccept(user -> {
105
-
System.out.println("user = "+ user);
106
-
userLoader.load(user.getInvitedByID())
107
-
.thenAccept(invitedBy -> {
108
-
System.out.println("invitedBy = "+ invitedBy);
109
-
});
110
-
});
111
-
112
-
userLoader.dispatch().join();
94
+
userLoader.load(1L)
95
+
.thenAccept(user -> {
96
+
System.out.println("user = "+ user);
97
+
userLoader.load(user.getInvitedByID())
98
+
.thenAccept(invitedBy -> {
99
+
System.out.println("invitedBy = "+ invitedBy);
100
+
});
101
+
});
102
+
103
+
userLoader.load(2L)
104
+
.thenAccept(user -> {
105
+
System.out.println("user = "+ user);
106
+
userLoader.load(user.getInvitedByID())
107
+
.thenAccept(invitedBy -> {
108
+
System.out.println("invitedBy = "+ invitedBy);
109
+
});
110
+
});
111
+
112
+
userLoader.dispatchAndJoin();
113
113
114
114
```
115
115
@@ -124,6 +124,13 @@ concurrent requests will be coalesced and presented to your batch loading functi
124
124
application to safely distribute data fetching requirements throughout your application and
125
125
maintain minimal outgoing data requests.
126
126
127
+
In the example above, the first call to dispatch will cause the batched user keys (1 and 2) to be fired at the BatchLoader function to load 2 users.
128
+
129
+
Since each `thenAccept` callback made more calls to `userLoader` to get the "user they they invited", another 2 user keys are fired at the BatchLoader function for them.
130
+
131
+
In this case the `userLoader.dispatchAndJoin()` is used to fire a dispatch call, wait for it (aka join it), see if the data loader has more batched entries, (which is does)
132
+
and then it repeats this until the data loader internal queue of keys is empty. At this point we have made 2 batched calls instead of the niave 4 calls we might have made if
0 commit comments