zio.kafka.consumer.diagnostics.Diagnostics.scala Maven / Gradle / Ivy
package zio.kafka.consumer.diagnostics
import zio.{ Queue, Scope, UIO, ZIO }
trait Diagnostics {
def emit(event: => DiagnosticEvent): UIO[Unit]
}
object Diagnostics {
case object NoOp extends Diagnostics {
override def emit(event: => DiagnosticEvent): UIO[Unit] = ZIO.unit
}
final case class SlidingQueue private (queue: Queue[DiagnosticEvent]) extends Diagnostics {
override def emit(event: => DiagnosticEvent): UIO[Unit] = queue.offer(event).unit
}
object SlidingQueue {
def make(queueSize: Int = 16): ZIO[Scope, Nothing, SlidingQueue] =
ZIO.acquireRelease(Queue.sliding[DiagnosticEvent](queueSize))(_.shutdown).map(SlidingQueue(_))
}
}