diff options
Diffstat (limited to 'async-http-client-handler/monix/src')
-rw-r--r-- | async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala b/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala index de0c139..30106f2 100644 --- a/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala +++ b/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala @@ -2,7 +2,7 @@ package com.softwaremill.sttp.asynchttpclient.monix import com.softwaremill.sttp.asynchttpclient.{ AsyncHttpClientHandler, - WrapperFromAsync + MonadAsyncError } import monix.eval.Task import monix.execution.Cancelable @@ -15,14 +15,21 @@ import org.asynchttpclient.{ import scala.util.{Failure, Success} class MonixAsyncHttpClientHandler(asyncHttpClient: AsyncHttpClient) - extends AsyncHttpClientHandler[Task](asyncHttpClient, TaskFromAsync) { + extends AsyncHttpClientHandler[Task](asyncHttpClient, TaskMonad) { def this() = this(new DefaultAsyncHttpClient()) def this(cfg: AsyncHttpClientConfig) = this(new DefaultAsyncHttpClient(cfg)) } -private[asynchttpclient] object TaskFromAsync extends WrapperFromAsync[Task] { - override def apply[T]( +private[monix] object TaskMonad extends MonadAsyncError[Task] { + override def unit[T](t: T): Task[T] = Task.now(t) + + override def map[T, T2](fa: Task[T], f: (T) => T2): Task[T2] = fa.map(f) + + override def flatMap[T, T2](fa: Task[T], f: (T) => Task[T2]): Task[T2] = + fa.flatMap(f) + + override def async[T]( register: ((Either[Throwable, T]) => Unit) => Unit): Task[T] = Task.async { (_, cb) => register { @@ -32,4 +39,6 @@ private[asynchttpclient] object TaskFromAsync extends WrapperFromAsync[Task] { Cancelable.empty } + + override def error[T](t: Throwable): Task[T] = Task.raiseError(t) } |