You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
package wow.doge.mygame
|
|
|
|
import sttp.capabilities.monix.MonixStreams
|
|
import sttp.client3._
|
|
import sttp.client3.asynchttpclient.monix._
|
|
|
|
import monix.eval.Task
|
|
import monix.reactive.Observable
|
|
import scala.concurrent.duration.Duration
|
|
import scala.collection.immutable.ArraySeq
|
|
import monix.reactive.Consumer
|
|
|
|
class WebsocketTest {
|
|
// : Task[Response[Either[String, Observable[Array[Byte]]]]]
|
|
|
|
val s = AsyncHttpClientMonixBackend().flatMap { backend =>
|
|
val response =
|
|
basicRequest
|
|
.post(uri"...")
|
|
.response(asStreamUnsafe(MonixStreams))
|
|
.readTimeout(Duration.Inf)
|
|
.send(backend)
|
|
response.map(_.body.map(_.map(ArraySeq.unsafeWrapArray)))
|
|
}
|
|
|
|
val MB = 1024 * 1024
|
|
def consumer(contentLength: Long): Consumer[ArraySeq[Byte], Long] =
|
|
Consumer.foldLeftEval(0L) {
|
|
case (sum, data) =>
|
|
val newSum = sum + data.length
|
|
for {
|
|
_ <- Task(
|
|
pprint.log(
|
|
s"Bytes downloaded = ${newSum * 1f / MB}MB . Percent done = ${(newSum * 100f / contentLength)
|
|
.formatted("%.2f")}"
|
|
)
|
|
)
|
|
} yield newSum
|
|
}
|
|
|
|
}
|