sttp.client4.impl.zio.ZioServerSentEvents.scala Maven / Gradle / Ivy
package sttp.client4.impl.zio
import sttp.capabilities.zio.ZioStreams
import sttp.model.sse.ServerSentEvent
import zio.stream.ZPipeline
object ZioServerSentEvents {
val parse: ZioStreams.Pipe[Byte, ServerSentEvent] = { stream =>
stream
.via(ZPipeline.utf8Decode)
.via(ZPipeline.splitLines)
.split(_.isEmpty)
.map(c => ServerSentEvent.parse(c.toList))
}
}