aboutsummaryrefslogtreecommitdiff
path: root/async-http-client-handler/scalaz
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-21 16:40:07 +0200
committeradamw <adam@warski.org>2017-07-21 16:40:07 +0200
commite5ebd242a4cb982af6b01ec1976ecfc91398189f (patch)
tree3ca28ad0c4409d05bf50c3059e783a08d0947153 /async-http-client-handler/scalaz
parent1e8b6064c3855a85c340165fad7feefaf656e074 (diff)
downloadsttp-e5ebd242a4cb982af6b01ec1976ecfc91398189f.tar.gz
sttp-e5ebd242a4cb982af6b01ec1976ecfc91398189f.tar.bz2
sttp-e5ebd242a4cb982af6b01ec1976ecfc91398189f.zip
Scalaz version of the async http client handler, wrapping responses in a Task
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))
+ }
+ }
+}