diff options
author | Sam Guymer <sam@guymer.me> | 2018-05-17 20:07:04 +1000 |
---|---|---|
committer | Sam Guymer <sam@guymer.me> | 2018-05-18 22:28:28 +1000 |
commit | 40288a1aaddfc27e141771371d69122ce222a8d0 (patch) | |
tree | 14177a51769ce42e88ec3d20435abe505b44aac5 /async-http-client-backend/scalaz/src/main/scala | |
parent | 96ff655f906f2e3f4e9ba906c42e96506f4668b9 (diff) | |
download | sttp-40288a1aaddfc27e141771371d69122ce222a8d0.tar.gz sttp-40288a1aaddfc27e141771371d69122ce222a8d0.tar.bz2 sttp-40288a1aaddfc27e141771371d69122ce222a8d0.zip |
Extract MonadAsyncError implementations
Extract MonadAsyncError implementations into their own projects to allow
reuse by multiple backends.
Diffstat (limited to 'async-http-client-backend/scalaz/src/main/scala')
-rw-r--r-- | async-http-client-backend/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazBackend.scala | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/async-http-client-backend/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazBackend.scala b/async-http-client-backend/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazBackend.scala index 7c2343d..db8731e 100644 --- a/async-http-client-backend/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazBackend.scala +++ b/async-http-client-backend/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazBackend.scala @@ -3,16 +3,16 @@ package com.softwaremill.sttp.asynchttpclient.scalaz import java.nio.ByteBuffer import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientBackend -import com.softwaremill.sttp.{FollowRedirectsBackend, MonadAsyncError, SttpBackend, SttpBackendOptions} +import com.softwaremill.sttp.impl.scalaz.TaskMonadAsyncError +import com.softwaremill.sttp.{FollowRedirectsBackend, SttpBackend, SttpBackendOptions} import io.netty.buffer.ByteBuf import org.asynchttpclient.{AsyncHttpClient, AsyncHttpClientConfig, DefaultAsyncHttpClient} import org.reactivestreams.Publisher import scalaz.concurrent.Task -import scalaz.{-\/, \/-} class AsyncHttpClientScalazBackend private (asyncHttpClient: AsyncHttpClient, closeClient: Boolean) - extends AsyncHttpClientBackend[Task, Nothing](asyncHttpClient, TaskMonad, closeClient) { + extends AsyncHttpClientBackend[Task, Nothing](asyncHttpClient, TaskMonadAsyncError, closeClient) { override protected def streamBodyToPublisher(s: Nothing): Publisher[ByteBuf] = s // nothing is everything @@ -37,25 +37,3 @@ object AsyncHttpClientScalazBackend { def usingClient(client: AsyncHttpClient): SttpBackend[Task, Nothing] = AsyncHttpClientScalazBackend(client, closeClient = false) } - -private[scalaz] object TaskMonad extends MonadAsyncError[Task] { - override def unit[T](t: T): Task[T] = Task.point(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(-\/(t)) - case Right(t) => cb(\/-(t)) - } - } - - override def error[T](t: Throwable): Task[T] = Task.fail(t) - - override protected def handleWrappedError[T](rt: Task[T])(h: PartialFunction[Throwable, Task[T]]): Task[T] = - rt.handleWith(h) -} |