MultipleResults is not type safe
tbee opened this issue · comments
When I sync two or more calls, the results are not provided in a type safe manner, and casting is needed:
.when( () -> callReturnsArrayOfStrings()
, () -> callReturnsArrayOfProjects() )
.done( (MultipleResults multipleResults) -> {
String[] templateNames = (String[])multipleResults.get(0).getResult();
Project[] projects = (Project[])multipleResults.get(1).getResult();
...
Other libraries have elected to use an API that is type safe, like RxJava:
Observable.zip( Observable.fromCallable( () ->callReturnsArrayOfStrings() )
, Observable.fromCallable( () -> callReturnsArrayOfProjects() )
, (String[] templateNames, Project[] projects) -> {
...
It would be nice if JDeferred also would be type safe, at least for common numbers of calls, like 2, 3, 4 and 5 or so.
Interesting suggestion. This would make the DeferredManager
's current API grow by a factory of 4 in order to support 2, 3, 4, 5, and 6+ arguments.
Currently most methods define varargs, this means they can be called with 0 or 1 elements too, must check if constraints (such as least 2 args have been supplied) are in place in the default implementation.
I suppose the 6+ variation will support typed args for 2 up to 5 and untyped for the rest (due to varargs).
What do you think @saturnism?