From e5ebd242a4cb982af6b01ec1976ecfc91398189f Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 21 Jul 2017 16:40:07 +0200 Subject: Scalaz version of the async http client handler, wrapping responses in a Task --- .../scalaz/ScalazAsyncHttpClientHandler.scala | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala (limited to 'async-http-client-handler/scalaz') diff --git a/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala b/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala new file mode 100644 index 0000000..e2c664c --- /dev/null +++ b/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala @@ -0,0 +1,32 @@ +package com.softwaremill.sttp.asynchttpclient.scalaz + +import com.softwaremill.sttp.asynchttpclient.internal.{ + AsyncHttpClientHandler, + WrapperFromAsync +} +import org.asynchttpclient.{ + AsyncHttpClient, + AsyncHttpClientConfig, + DefaultAsyncHttpClient +} + +import scalaz.{-\/, \/-} +import scalaz.concurrent.Task + +class ScalazAsyncHttpClientHandler(asyncHttpClient: AsyncHttpClient) + extends AsyncHttpClientHandler[Task](asyncHttpClient, TaskFromAsync) { + + def this() = this(new DefaultAsyncHttpClient()) + def this(cfg: AsyncHttpClientConfig) = this(new DefaultAsyncHttpClient(cfg)) +} + +private[asynchttpclient] object TaskFromAsync extends WrapperFromAsync[Task] { + override def apply[T]( + register: ((Either[Throwable, T]) => Unit) => Unit): Task[T] = + Task.async { cb => + register { + case Left(t) => cb(-\/(t)) + case Right(t) => cb(\/-(t)) + } + } +} -- cgit v1.2.3