Skip to content
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

fromFuture usage #38

Closed
gabro opened this issue Dec 20, 2016 · 3 comments
Closed

fromFuture usage #38

gabro opened this issue Dec 20, 2016 · 3 comments

Comments

@gabro
Copy link

gabro commented Dec 20, 2016

Hey there, I've seen https://github.com/atnos-org/eff/blob/957fe5b514ee4afa6683fb803772234870749bb6/shared/src/main/scala/org/atnos/eff/AsyncFutureInterpreter.scala and I'm trying to figure out how to use fromFuture.

I have a few methods returning Future and I'd like to incorporate them inside my effect.

So, what I have so far is

  val interpreter = {
    import scala.concurrent.ExecutionContext.Implicits.global
    AsyncFutureInterpreter.create
  }
  import interpreter._

  def program[R : _config : _log : _async]: Eff[R, Future[String]] = for {
    config <- ask[R, Config]
    ip <- fromFuture(connect(config))
    _ <- tell(s"Listening on ${config.host}:${config.port}")
  } yield ip

and this compiles.

However, the fromFuture method comes from import interpreter._. So here I'm coupling the interpreter and the effect building.

Is there a way of working with existing futures in without coupling the specific interpreter?

@edmundnoble
Copy link
Contributor

edmundnoble commented Dec 20, 2016

fromFuture is not an interpreter method, just because it belongs to the interpreter. It's a case of bad names. If you are working with Futures in Eff through Async, then you are working with the Future Async interpreter; it not only specifies how to get values out of an Eff value (interpretation), but how to get them in. They are tightly coupled, and that is the biggest reason I don't like Async.

If you don't want to use Async, you might be interested in trying bare Future.

@gabro
Copy link
Author

gabro commented Dec 21, 2016

It makes sense, thanks for the answer!

@gabro gabro closed this as completed Dec 21, 2016
@etorreborre
Copy link
Member

I agree this is not so nice and we should split the creation from the interpretation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants