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

Better Implicits Management #70

Closed
juanpedromoreno opened this issue Oct 29, 2017 · 0 comments
Closed

Better Implicits Management #70

juanpedromoreno opened this issue Oct 29, 2017 · 0 comments
Assignees

Comments

@juanpedromoreno
Copy link
Member

At this moment, users of frees-rpc have to define several implicits that are repeated once again.

We could offer them just importing:

import freestyle.rpc.server.implicits._ or import freestyle.rpc.client.implicits._, depending on the case.

For example, something like the following can be provided by the library:

trait FutureInstances extends freestyle.rpc.client.FutureInstances {

  protected val atMostDuration: FiniteDuration = 10.seconds

  implicit def futureComonad(implicit ec: ExecutionContext): Comonad[Future] =
    new Comonad[Future] {
      def extract[A](x: Future[A]): A = {
        logger.info(s"${Thread.currentThread().getName} Waiting $atMostDuration for $x...")
        Await.result(x, atMostDuration)
      }

      override def coflatMap[A, B](fa: Future[A])(f: (Future[A]) => B): Future[B] = Future(f(fa))

      override def map[A, B](fa: Future[A])(f: (A) => B): Future[B] =
        fa.map(f)
    }

  implicit val future2Task: Future ~> Task =
    new (Future ~> Task) {
      override def apply[A](fa: Future[A]): Task[A] = {
        logger.info(s"${Thread.currentThread().getName} Deferring Future to Task...")
        Task.deferFuture(fa)
      }
    }
}

Here, perhaps:

https://github.com/frees-io/freestyle-rpc/blob/5180a8f88785cf55a636bfe18269cbbf6b7b1b2a/rpc/src/main/scala/client/implicits.scala#L28-L35

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

1 participant