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
Nifty implicit conversions to Scala's Future to IO #173
Comments
we already have that conversion |
I am aware of that but looked a little bit of cumbersome IMO and also remain the proposal to add a implicit conversion. final implicit class FutureOps[+T](f: Future[T]) {
final def toIO: IO[T] = final def toIO: IO[T] = IO.fromFuture(IO(f))
} |
I don't think implicit conversions are a good feature especially in a library as general as The problem with this conversion is basically that it looks like you're delaying all effects untill you actually run an |
@hilios note that your implementation does not reflect the reality, which should be: IO.fromFuture(IO.pure(f))
def fromFuture[A](fa: Future[A]): IO[A] This is because the signature makes the evaluation model pretty clear imo and the IDE shows you the type of that parameter as soon as you have to supply it. And also in terms of naming, this is pretty clear: IO.fromFuture(launchMissiles()) But then such a function is much more explicit than the extension method that you're proposing here. launchMissiles().toIO Usability is not good, because the signature of If this will ever happen, it will happen part of a type-class like the one proposed at #73; when I wrote that issue, I was thinking of Also in the case of |
Guys, thanks so much for so elucidative and prompt feedback. I agree that the implicit might cause the wrong impression because of the Future’s default behavior and a type class would be the preferred way to go in this matter. Cheers. |
Just wanted to drop here that I was using Using the solution here by @hilios instead of Not saying that |
@monzonj Are you running blocking code in the futures? |
Hi @vasilmkd thanks for replying Inside the future there is some IO, but even without any blocking the
I will try to create an isolated http4s app with this code to see if it's a real issue, or just the setup of my project. |
If you can, please create a small app, note the versions of the libraries used (preferably a small sbt project) and we'll take a look. A reason why The reason why using the code from this post "works" is because the Futures that you create start execution immediately upon their declaration (I'm guessing you had to add the |
Hi @vasilmkd Indeed I'm using @alexandru using http4s |
@monzonj This definitely seems concerning! Would you mind opening a new issue and adding whatever details you can? It's particularly helpful if you can get anything approaching a shareable reproducer. My guess based on very little other than spidey sense is the same as Vasil's: it's probably some blocking operation within the |
I've been lifting the in Scala's
Future
toAsync
for a while now and came up with a simple implicit conversion for this:I was wondering if this is probably such common pattern in our daily work – that requires us to interact with libraries that expose
Futures
– so would make sense to add to thecats.effect.implicits
package.Do you guys have anything against adding this conversion?
If not so, let me know what the guidelines I should follow to submit a PR and contribute to this awesome project.
Thanks in advance!
The text was updated successfully, but these errors were encountered: