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
Is it possible to convert an async operation (e.g. fetch records from a database and wrap in a future) to an Either or a Maybe?
If not, is it on the roadmap? Why or why not?
I discovered IO.externallyManaged() but it requires me to invoke Future.get() on my future. I am looking for a way to use the palatable/lambda API exclusively to invoke my async calls.
Thanks
The text was updated successfully, but these errors were encountered:
Either<Throwable, A> either = Try.trying(myFuture::get).toEither(); // or .toMaybe()
If so, in general I would avoid that, since the Future almost certainly represents a side-effect, and I tend to keep impure operations separate from pure operations. In this case, I would lift the Future into an IO:
IO<Either<Throwable, A>> io = io(myFuture::get).safe(); // or .fmap(Either::toMaybe)
Now, this is about the best you can do if all you have is a Future. Future is a miserable type precisely because it offers no interface for composition or callbacks, which severely limits what can be done with it that doesn't require a call to Future#get.
However, if you had a CompletableFuture, I can lift that into an IO directly via the mechanism that you've already discovered, IO#externallyManaged.
Once you're in IO, you should have no trouble at all wrapping the result in an Either, or a Maybe, or whatever you choose.
So, is the challenge that you just have a Future, and not a CompletableFuture, and you also don't want to call Future#get? If so, I have personally gone to great lengths in the past to proxy Future with CompletableFuture at the expense of a single JVM thread acting as an event loop or selector (think of it as epoll for futures) that connects CompletableFutures to their proxied Future, and I can explain how that worked if you're interested, but that code is not in lambda, and I probably wouldn't put it in lambda since it would require lambda taking one of your threads away from you at start up time.
If you'd like to discuss this in real time, if that's easier, please join me in the lambda gitter and we can chat about this: https://gitter.im/palatable/lambda
Is it possible to convert an async operation (e.g. fetch records from a database and wrap in a future) to an
Either
or aMaybe
?If not, is it on the roadmap? Why or why not?
I discovered
IO.externallyManaged()
but it requires me to invokeFuture.get()
on my future. I am looking for a way to use the palatable/lambda API exclusively to invoke my async calls.Thanks
The text was updated successfully, but these errors were encountered: