fadas.sjsls_3.0.2.1.source-code.refresh.route.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sjsls_3 Show documentation
Show all versions of sjsls_3 Show documentation
An experimental live server for scala JS projects
The newest version!
package io.github.quafadas.sjsls
import scala.concurrent.duration.DurationInt
import org.http4s.HttpRoutes
import org.http4s.ServerSentEvent
import org.http4s.dsl.io.*
import fs2.concurrent.Topic
import cats.effect.IO
import _root_.io.circe.syntax.EncoderOps
def refreshRoutes(refreshTopic: Topic[IO, Unit]) = HttpRoutes.of[IO] {
case GET -> Root / "refresh" / "v1" / "sse" =>
val keepAlive = fs2.Stream.fixedRate[IO](10.seconds).as(KeepAlive())
Ok(
keepAlive
.merge(refreshTopic.subscribe(10).as(PageRefresh()))
.map(msg => ServerSentEvent(Some(msg.asJson.noSpaces)))
)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy