All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sttp.client4.impl.monix.MonixSimpleQueue.scala Maven / Gradle / Ivy

package sttp.client4.impl.monix

import monix.eval.Task
import monix.execution.{AsyncQueue => MAsyncQueue, Scheduler}
import sttp.client4.internal.ws.SimpleQueue
import sttp.ws.WebSocketBufferFull

class MonixSimpleQueue[A](bufferCapacity: Option[Int])(implicit s: Scheduler) extends SimpleQueue[Task, A] {
  private val queue = bufferCapacity match {
    case Some(capacity) => MAsyncQueue.bounded[A](capacity)
    case None           => MAsyncQueue.unbounded[A]()
  }

  override def offer(t: A): Unit =
    if (!queue.tryOffer(t)) {
      throw WebSocketBufferFull(bufferCapacity.getOrElse(Int.MaxValue))
    }
  override def poll: Task[A] = Task.deferFuture(queue.poll())
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy