ossgang / ossgang-commons

Apache License 2.0
4 stars 0 forks source link

AsyncMaybe<Void> fail with some operators #54

Closed andreacalia closed 4 years ago

andreacalia commented 4 years ago

The case of Void is particularly complex since the Maybe interface will not accept it as a value.. Since behind the scenes an AsyncMaybe is a CompletableFuture, the API doesn't make the difference between Void or T and null is always allowed.

As an example, the following piece of code fails on the .toMaybeBlocking() since it is trying to assign null as a value of the Maybe:

AsyncMaybe.attemptAsync(() -> System.out.println("Ok"))
                .whenException(e -> System.err.println("Err"))
                .toMaybeBlocking().throwOnException();
andreacalia commented 4 years ago

Now the AsyncMaybe implementation completely bypass the CompletableFuture exception management and relies entirely on Maybes :smile: The CompletableFuture is still used to handle the async processing..

andreacalia commented 4 years ago

I will still make some small tweaks and then merge if you agree @michi42 :smile: