diff options
author | adamw <adam@warski.org> | 2017-07-24 12:18:27 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-24 12:18:27 +0200 |
commit | ccd2c4b1d53bf68e04ff1f8bca032d870494d9a8 (patch) | |
tree | e298b14664b07dc9aab54f74abe956fb797fe1bb /async-http-client-handler/monix/src | |
parent | fef16dd2dbd0f53ee7432ab2ff39255279932ac4 (diff) | |
download | sttp-ccd2c4b1d53bf68e04ff1f8bca032d870494d9a8.tar.gz sttp-ccd2c4b1d53bf68e04ff1f8bca032d870494d9a8.tar.bz2 sttp-ccd2c4b1d53bf68e04ff1f8bca032d870494d9a8.zip |
Better responseAs mapping, done on the client thread pool
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) } |