diff options
author | Adam Warski <adam@warski.org> | 2018-05-18 15:52:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-18 15:52:12 +0200 |
commit | 588395d018c258eb74f60ad95bad706698bdf915 (patch) | |
tree | 2c4ee642d8efb9e6785da3fe8a7decba507329ab /async-http-client-backend/monix | |
parent | 96ff655f906f2e3f4e9ba906c42e96506f4668b9 (diff) | |
parent | 5980017ece9be1ebf30775e5babf81e0e2f1fcd9 (diff) | |
download | sttp-588395d018c258eb74f60ad95bad706698bdf915.tar.gz sttp-588395d018c258eb74f60ad95bad706698bdf915.tar.bz2 sttp-588395d018c258eb74f60ad95bad706698bdf915.zip |
Merge pull request #93 from guymers/scalajs-1
Extract MonadAsyncError implementations
Diffstat (limited to 'async-http-client-backend/monix')
-rw-r--r-- | async-http-client-backend/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixBackend.scala | 40 |
1 files changed, 4 insertions, 36 deletions
diff --git a/async-http-client-backend/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixBackend.scala b/async-http-client-backend/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixBackend.scala index 915b325..a181517 100644 --- a/async-http-client-backend/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixBackend.scala +++ b/async-http-client-backend/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixBackend.scala @@ -3,26 +3,18 @@ package com.softwaremill.sttp.asynchttpclient.monix import java.nio.ByteBuffer import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientBackend -import com.softwaremill.sttp.{ - FollowRedirectsBackend, - MonadAsyncError, - SttpBackend, - SttpBackendOptions, - Utf8, - concatByteBuffers -} +import com.softwaremill.sttp.impl.monix.TaskMonadAsyncError +import com.softwaremill.sttp.{FollowRedirectsBackend, SttpBackend, SttpBackendOptions, Utf8, concatByteBuffers} import io.netty.buffer.{ByteBuf, Unpooled} import monix.eval.Task -import monix.execution.{Cancelable, Scheduler} +import monix.execution.Scheduler import monix.reactive.Observable import org.asynchttpclient.{AsyncHttpClient, AsyncHttpClientConfig, DefaultAsyncHttpClient} import org.reactivestreams.Publisher -import scala.util.{Failure, Success} - class AsyncHttpClientMonixBackend private (asyncHttpClient: AsyncHttpClient, closeClient: Boolean)( implicit scheduler: Scheduler) - extends AsyncHttpClientBackend[Task, Observable[ByteBuffer]](asyncHttpClient, TaskMonad, closeClient) { + extends AsyncHttpClientBackend[Task, Observable[ByteBuffer]](asyncHttpClient, TaskMonadAsyncError, closeClient) { override protected def streamBodyToPublisher(s: Observable[ByteBuffer]): Publisher[ByteBuf] = s.map(Unpooled.wrappedBuffer).toReactivePublisher @@ -70,27 +62,3 @@ object AsyncHttpClientMonixBackend { implicit s: Scheduler = Scheduler.Implicits.global): SttpBackend[Task, Observable[ByteBuffer]] = AsyncHttpClientMonixBackend(client, closeClient = false) } - -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 { - case Left(t) => cb(Failure(t)) - case Right(t) => cb(Success(t)) - } - - Cancelable.empty - } - - override def error[T](t: Throwable): Task[T] = Task.raiseError(t) - - override protected def handleWrappedError[T](rt: Task[T])(h: PartialFunction[Throwable, Task[T]]): Task[T] = - rt.onErrorRecoverWith(h) -} |