cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Add `Async#fromJavaFuture`

Open armanbilge opened this issue 3 years ago • 3 comments

~~Still needs some tests.~~ /cc @Daenyth

armanbilge avatar Jun 19 '22 14:06 armanbilge

I'm a little on the fence about this one. IMO if we're going to do it, we should at least double-check to see if the Future is secretly a CompletableFuture, to avoid creating a foot gun.

djspiewak avatar Jun 19 '22 17:06 djspiewak

Oh, I missed the fact that CompletableFuture extends Future. Fair point.

armanbilge avatar Jun 19 '22 17:06 armanbilge

For the record I'm skeptical about this one too now. Somebody asked on the Discord about just Future and the cancellation logic doesn't come for free so it seemed worth adding.

armanbilge avatar Jun 19 '22 17:06 armanbilge

More thoughts from Daniel:

second, it makes it seem like it's fine to convert from Future to IO, in the same way that it is with CF when really it's not this in turn may lead users to select APIs which return Future rather than CF since they seem equivalent basically the argument is that putting something in the API elevates the case to something more "supported" and "okay" but really it's not okay. it's terrible. sometimes you have to do it, but not often

So that seems like a convincing argument not to add this. The workaround is to do IO.blocking(future.get()) or inline what I have here if you want cancelation.

armanbilge avatar Oct 22 '22 16:10 armanbilge