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

Adds monix.eval.Task Comonad Implicit Evidence #89

Merged
merged 1 commit into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions rpc/src/main/scala/RPCAsyncImplicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package freestyle
package rpc

import cats.{~>, Comonad}
import freestyle.async.AsyncContext
import freestyle.rpc.client.handlers._
import journal.Logger
import monix.eval.Task
Expand All @@ -33,7 +32,7 @@ trait RPCAsyncImplicits extends freestyle.async.Implicits {
protected[this] val asyncLogger: Logger = Logger[this.type]
protected[this] val atMostDuration: FiniteDuration = 10.seconds

implicit def futureComonad(implicit ec: ExecutionContext): Comonad[Future] =
implicit def futureComonad(implicit EC: ExecutionContext): Comonad[Future] =
new Comonad[Future] {
def extract[A](x: Future[A]): A = {
asyncLogger.info(s"${Thread.currentThread().getName} Waiting $atMostDuration for $x...")
Expand All @@ -46,6 +45,19 @@ trait RPCAsyncImplicits extends freestyle.async.Implicits {
fa.map(f)
}

implicit def taskComonad(implicit S: Scheduler): Comonad[Task] =
new Comonad[Task] {
def extract[A](x: Task[A]): A = {
asyncLogger.info(s"${Thread.currentThread().getName} Waiting $atMostDuration for $x...")
Await.result(x.runAsync, atMostDuration)
}

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

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

implicit def task2Future(implicit S: Scheduler): FSHandler[Task, Future] =
new TaskMHandler[Future]

Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.3.4-SNAPSHOT"
version in ThisBuild := "0.3.4"