diff options
author | adamw <adam@warski.org> | 2017-07-21 17:04:18 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-21 17:04:18 +0200 |
commit | ec33423b3bc212292768c77c2a7a67715664f4e7 (patch) | |
tree | 3cdcd69bb81cc4a95706706367a446b3b4bc3ead /async-http-client-handler/monix/src/main | |
parent | e5ebd242a4cb982af6b01ec1976ecfc91398189f (diff) | |
download | sttp-ec33423b3bc212292768c77c2a7a67715664f4e7.tar.gz sttp-ec33423b3bc212292768c77c2a7a67715664f4e7.tar.bz2 sttp-ec33423b3bc212292768c77c2a7a67715664f4e7.zip |
Monix handler
Diffstat (limited to 'async-http-client-handler/monix/src/main')
-rw-r--r-- | async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala | 35 |
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 + } +} |