aboutsummaryrefslogtreecommitdiff
path: root/async-http-client-handler/scalaz
diff options
context:
space:
mode:
Diffstat (limited to 'async-http-client-handler/scalaz')
-rw-r--r--async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala32
1 files changed, 32 insertions, 0 deletions
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))
+ }
+ }
+}