blob: e2c664c36b95ae08a6c7a1f55f88c19b673d4398 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package com.softwaremill.sttp.asynchttpclient.scalaz
import com.softwaremill.sttp.asynchttpclient.internal.{
AsyncHttpClientHandler,
WrapperFromAsync
}
import org.asynchttpclient.{
AsyncHttpClient,
AsyncHttpClientConfig,
DefaultAsyncHttpClient
}
import scalaz.{-\/, \/-}
import scalaz.concurrent.Task
class ScalazAsyncHttpClientHandler(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(-\/(t))
case Right(t) => cb(\/-(t))
}
}
}
|