aboutsummaryrefslogtreecommitdiff
path: root/async-http-client-handler/future/src/main/scala/com/softwaremill
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/future/src/main/scala/com/softwaremill
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/future/src/main/scala/com/softwaremill')
-rw-r--r--async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala33
1 files changed, 33 insertions, 0 deletions
diff --git a/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala b/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala
new file mode 100644
index 0000000..624c51b
--- /dev/null
+++ b/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala
@@ -0,0 +1,33 @@
+package com.softwaremill.sttp.asynchttpclient.future
+
+import com.softwaremill.sttp.asynchttpclient.internal.{
+ AsyncHttpClientHandler,
+ WrapperFromAsync
+}
+import org.asynchttpclient.{
+ AsyncHttpClient,
+ AsyncHttpClientConfig,
+ DefaultAsyncHttpClient
+}
+
+import scala.concurrent.{Future, Promise}
+
+class FutureAsyncHttpClientHandler(asyncHttpClient: AsyncHttpClient)
+ extends AsyncHttpClientHandler[Future](asyncHttpClient, FutureFromAsync) {
+
+ def this() = this(new DefaultAsyncHttpClient())
+ def this(cfg: AsyncHttpClientConfig) = this(new DefaultAsyncHttpClient(cfg))
+}
+
+private[asynchttpclient] object FutureFromAsync
+ extends WrapperFromAsync[Future] {
+ override def apply[T](
+ register: ((Either[Throwable, T]) => Unit) => Unit): Future[T] = {
+ val p = Promise[T]()
+ register {
+ case Left(t) => p.failure(t)
+ case Right(t) => p.success(t)
+ }
+ p.future
+ }
+}