Some Name
Some Name

Reputation: 9540

Bounded priority queue in ZIO

There is TPriorityQueue in ZIO which is unbounded. Is there a way to adapt it to become bounded?

Upvotes: 1

Views: 201

Answers (1)

gurghet
gurghet

Reputation: 7706

If you don't care about performance too much you can do something quick and dirty like this:

case class TPW(tpq: TPriorityQueue[Int]) {
  def offer(e: Int) = ZSTM.whenM(tpq.size.map(_ < 50))(tpq.offer(e))
  // .. other methods
}

This would be a dropping queue.

Upvotes: 1

Related Questions