aboutsummaryrefslogtreecommitdiff
path: root/async-http-client-handler/monix/src
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-24 17:01:20 +0200
committeradamw <adam@warski.org>2017-07-24 17:01:20 +0200
commitb5f0c5387f7a98875f60fdf09c8dbe56e5c2766d (patch)
treedbfe91d274ed38ad1a85dceb4f3092bc8dc80a9b /async-http-client-handler/monix/src
parentb1a539bd1fb5a5870c2e96c73f14e79b6caf4ff6 (diff)
downloadsttp-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/monix/src')
-rw-r--r--async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala16
1 files changed, 10 insertions, 6 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
index c77e6d9..8e6c70d 100644
--- 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
@@ -18,11 +18,13 @@ import org.reactivestreams.Publisher
import scala.util.{Failure, Success}
-class MonixAsyncHttpClientHandler private (asyncHttpClient: AsyncHttpClient)(
- implicit scheduler: Scheduler)
+class MonixAsyncHttpClientHandler private (
+ asyncHttpClient: AsyncHttpClient,
+ closeClient: Boolean)(implicit scheduler: Scheduler)
extends AsyncHttpClientHandler[Task, Observable[ByteBuffer]](
asyncHttpClient,
- TaskMonad) {
+ TaskMonad,
+ closeClient) {
override protected def streamBodyToPublisher(
s: Observable[ByteBuffer]): Publisher[ByteBuffer] = {
@@ -42,7 +44,8 @@ object MonixAsyncHttpClientHandler {
*/
def apply()(implicit s: Scheduler = Scheduler.Implicits.global)
: MonixAsyncHttpClientHandler =
- new MonixAsyncHttpClientHandler(new DefaultAsyncHttpClient())
+ new MonixAsyncHttpClientHandler(new DefaultAsyncHttpClient(),
+ closeClient = true)
/**
* @param s The scheduler used for streaming request bodies. Defaults to the
@@ -51,7 +54,8 @@ object MonixAsyncHttpClientHandler {
def usingConfig(cfg: AsyncHttpClientConfig)(implicit s: Scheduler =
Scheduler.Implicits.global)
: MonixAsyncHttpClientHandler =
- new MonixAsyncHttpClientHandler(new DefaultAsyncHttpClient())
+ new MonixAsyncHttpClientHandler(new DefaultAsyncHttpClient(),
+ closeClient = true)
/**
* @param s The scheduler used for streaming request bodies. Defaults to the
@@ -60,7 +64,7 @@ object MonixAsyncHttpClientHandler {
def usingClient(client: AsyncHttpClient)(implicit s: Scheduler =
Scheduler.Implicits.global)
: MonixAsyncHttpClientHandler =
- new MonixAsyncHttpClientHandler(client)
+ new MonixAsyncHttpClientHandler(client, closeClient = false)
}
private[monix] object TaskMonad extends MonadAsyncError[Task] {