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/cats/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/cats/src/main/scala')
-rw-r--r-- | async-http-client-backend/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsBackend.scala | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/async-http-client-backend/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsBackend.scala b/async-http-client-backend/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsBackend.scala index 506ad42..0e5955a 100644 --- a/async-http-client-backend/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsBackend.scala +++ b/async-http-client-backend/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsBackend.scala @@ -2,9 +2,10 @@ package com.softwaremill.sttp.asynchttpclient.cats import java.nio.ByteBuffer -import cats.effect._ +import cats.effect.Async import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientBackend -import com.softwaremill.sttp.{FollowRedirectsBackend, MonadAsyncError, SttpBackend, SttpBackendOptions} +import com.softwaremill.sttp.impl.cats.AsyncMonadAsyncError +import com.softwaremill.sttp.{FollowRedirectsBackend, SttpBackend, SttpBackendOptions} import io.netty.buffer.ByteBuf import org.asynchttpclient.{AsyncHttpClient, AsyncHttpClientConfig, DefaultAsyncHttpClient} import org.reactivestreams.Publisher @@ -16,7 +17,7 @@ class AsyncHttpClientCatsBackend[F[_]: Async] private ( closeClient: Boolean ) extends AsyncHttpClientBackend[F, Nothing]( asyncHttpClient, - new AsyncMonad, + new AsyncMonadAsyncError, closeClient ) { override protected def streamBodyToPublisher(s: Nothing): Publisher[ByteBuf] = @@ -43,21 +44,3 @@ object AsyncHttpClientCatsBackend { def usingClient[F[_]: Async](client: AsyncHttpClient): SttpBackend[F, Nothing] = AsyncHttpClientCatsBackend(client, closeClient = false) } - -private[cats] class AsyncMonad[F[_]](implicit F: Async[F]) extends MonadAsyncError[F] { - - override def async[T](register: ((Either[Throwable, T]) => Unit) => Unit): F[T] = - F.async(register) - - override def unit[T](t: T): F[T] = F.pure(t) - - override def map[T, T2](fa: F[T])(f: (T) => T2): F[T2] = F.map(fa)(f) - - override def flatMap[T, T2](fa: F[T])(f: (T) => F[T2]): F[T2] = - F.flatMap(fa)(f) - - override def error[T](t: Throwable): F[T] = F.raiseError(t) - - override protected def handleWrappedError[T](rt: F[T])(h: PartialFunction[Throwable, F[T]]): F[T] = - F.recoverWith(rt)(h) -} |