diff options
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.scala | 33 |
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 + } +} |