diff options
author | adamw <adam@warski.org> | 2017-07-24 17:01:20 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-24 17:01:20 +0200 |
commit | b5f0c5387f7a98875f60fdf09c8dbe56e5c2766d (patch) | |
tree | dbfe91d274ed38ad1a85dceb4f3092bc8dc80a9b /async-http-client-handler/future | |
parent | b1a539bd1fb5a5870c2e96c73f14e79b6caf4ff6 (diff) | |
download | sttp-b5f0c5387f7a98875f60fdf09c8dbe56e5c2766d.tar.gz sttp-b5f0c5387f7a98875f60fdf09c8dbe56e5c2766d.tar.bz2 sttp-b5f0c5387f7a98875f60fdf09c8dbe56e5c2766d.zip |
Closing the async http client if created by sttp
Diffstat (limited to 'async-http-client-handler/future')
-rw-r--r-- | async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala | 16 |
1 files changed, 10 insertions, 6 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 index a2e49a2..11808d3 100644 --- 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 @@ -15,10 +15,12 @@ import org.reactivestreams.Publisher import scala.concurrent.{ExecutionContext, Future, Promise} -class FutureAsyncHttpClientHandler private (asyncHttpClient: AsyncHttpClient)( - implicit ec: ExecutionContext) +class FutureAsyncHttpClientHandler private ( + asyncHttpClient: AsyncHttpClient, + closeClient: Boolean)(implicit ec: ExecutionContext) extends AsyncHttpClientHandler[Future, Nothing](asyncHttpClient, - new FutureMonad()) { + new FutureMonad(), + closeClient) { override protected def streamBodyToPublisher( s: Nothing): Publisher[ByteBuffer] = s // nothing is everything @@ -38,7 +40,8 @@ object FutureAsyncHttpClientHandler { def apply()( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : FutureAsyncHttpClientHandler = - new FutureAsyncHttpClientHandler(new DefaultAsyncHttpClient()) + new FutureAsyncHttpClientHandler(new DefaultAsyncHttpClient(), + closeClient = true) /** * @param ec The execution context for running non-network related operations, @@ -48,7 +51,8 @@ object FutureAsyncHttpClientHandler { def usingConfig(cfg: AsyncHttpClientConfig)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : FutureAsyncHttpClientHandler = - new FutureAsyncHttpClientHandler(new DefaultAsyncHttpClient()) + new FutureAsyncHttpClientHandler(new DefaultAsyncHttpClient(), + closeClient = true) /** * @param ec The execution context for running non-network related operations, @@ -58,7 +62,7 @@ object FutureAsyncHttpClientHandler { def usingClient(client: AsyncHttpClient)(implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : FutureAsyncHttpClientHandler = - new FutureAsyncHttpClientHandler(client) + new FutureAsyncHttpClientHandler(client, closeClient = false) } private[future] class FutureMonad(implicit ec: ExecutionContext) |