The object type returned by DataLoaderFactory.newDataLoaderWithTry().dispatcher is inconsistent with the specified generic type.
Describe the bug
I am new to this library. When learning this library, I found that the object type returned by DataLoaderFactory.newDataLoaderWithTry().dispatcher() is inconsistent with the specified generic type.
To Reproduce
You are right - is is inconsistent when the Try mechanism is used
Data loader is declared as DataLoader<K, V> and hence we get public CompletableFuture<List<V>> dispatch()
The Try wrappers are unwrapped by the engine code and hence the CompletableFuture<V> load(K key) values do come back as the expected V type but the dispatch gives back the raw values and does not unwrap them.
} else if (value instanceof Try) {
// we allow the batch loader to return a Try so we can better represent a computation
// that might have worked or not.
Try<V> tryValue = (Try<V>) value;
if (tryValue.isSuccess()) {
future.complete(tryValue.get());
} else {
stats.incrementLoadErrorCount(new IncrementLoadErrorCountStatisticsContext<>(key, callContext));
future.completeExceptionally(tryValue.getThrowable());
clearCacheKeys.add(keys.get(idx));
}
Perhaps it should unwrap them when giving his back - I would have to think on that more.
The other option would be to have something like DataLoader<K,V,BatchV> where BatchV is the generic type of value coming back from the BatchLoader but thats too viral a change really.
ps. We mostly expect people to use the values via load(k) calls rather than the values coming back via dispatch but you are right its inconsistent.
Hello, this issue has been inactive for 60 days, so we're marking it as stale. If you would like to continue this discussion, please comment within the next 30 days or we'll close the issue.
Hello, as this issue has been inactive for 90 days, we're closing the issue. If you would like to resume the discussion, please create a new issue.