aboutsummaryrefslogtreecommitdiff
path: root/async-http-client-handler
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-21 17:04:18 +0200
committeradamw <adam@warski.org>2017-07-21 17:04:18 +0200
commitec33423b3bc212292768c77c2a7a67715664f4e7 (patch)
tree3cdcd69bb81cc4a95706706367a446b3b4bc3ead /async-http-client-handler
parente5ebd242a4cb982af6b01ec1976ecfc91398189f (diff)
downloadsttp-ec33423b3bc212292768c77c2a7a67715664f4e7.tar.gz
sttp-ec33423b3bc212292768c77c2a7a67715664f4e7.tar.bz2
sttp-ec33423b3bc212292768c77c2a7a67715664f4e7.zip
Monix handler
Diffstat (limited to 'async-http-client-handler')
-rw-r--r--async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala35
1 files changed, 35 insertions, 0 deletions
diff --git a/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala b/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala
new file mode 100644
index 0000000..ddfacb5
--- /dev/null
+++ b/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala
@@ -0,0 +1,35 @@
+package com.softwaremill.sttp.asynchttpclient.monix
+
+import com.softwaremill.sttp.asynchttpclient.internal.{
+ AsyncHttpClientHandler,
+ WrapperFromAsync
+}
+import monix.eval.Task
+import monix.execution.Cancelable
+import org.asynchttpclient.{
+ AsyncHttpClient,
+ AsyncHttpClientConfig,
+ DefaultAsyncHttpClient
+}
+
+import scala.util.{Failure, Success}
+
+class MonixAsyncHttpClientHandler(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(Failure(t))
+ case Right(t) => cb(Success(t))
+ }
+
+ Cancelable.empty
+ }
+}