-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Opinion solicitation] How should the api converting from third part object to Promise look like? #2
Comments
Every implementation module could expose "java service loader" services (https://docs.oracle.com/javase/9/docs/api/java/util/ServiceLoader.html). In the |
@mojo2012 But an object argument is ugly and error-prone. And the error will be found until runtime. |
I’m just coming across this project out of curiosity, as I’m discovering WebFlux and I saw your comment on electronicarts/ea-async#54. Just to add my 2 cents:
This would considerably reduce the impact on the code, only needing to import that static method. Consider the first EA Async example from their homepage: public CompletableFuture<Boolean> buyItem(String itemTypeId, int cost)
{
if(!await(bank.decrement(cost))) {
return completedFuture(false);
}
await(inventory.giveItem(itemTypeId));
return completedFuture(true);
} vs your example: @Async()
private JPromise<Double> _getEmployeeTotalSalaryByDepartment(String department) {
double money = 0.0;
Mono<List<Employee>> empsMono = employeeRepository.findEmployeeByDepartment(department);
JPromise<List<Employee>> empsPromise = Promises.from(empsMono);
for (Employee employee : empsPromise.await()) {
Salary salary = Promises.from(salaryRepository.findSalaryByEmployee(employee.id)).await();
money += salary.total;
}
return JAsync.just(money);
} with a static private Mono<Double> _getEmployeeTotalSalaryByDepartment(String department) {
double money = 0.0;
List<Employee> emps = await(employeeRepository.findEmployeeByDepartment(department));
for (Employee employee : emps ) {
Salary salary = await(salaryRepository.findSalaryByEmployee(employee.id)));
money += salary.total;
}
return Mono.just(money);
} which is much more readable and does not clutter the code with foreign types. |
The implementation module which wrap the third part library such as Reactor or JxJava should be completely isolated from the core module. In other words, the implementation module should depend on core module, but the core module should not depend on the implementation module. This cause a problem, I don't know how should the api converting from third part object to Promise look like.
<T> Promise<T> JAsync.from(Object)
in the core module. Obviously this is ugly and error-prone. But the fact that apis are aggregated together is an advantage.<T> Promise<T> Promises.from(XXX<T> from)
in the implementation module, whereXXX
may beMono
orSingle
orFuture
. This API makes perfect use of generics and looks more reliable but it doesn't make for a unified API.The text was updated successfully, but these errors were encountered: