fs2
fs2 copied to clipboard
Documentation: Add information about `Channel`
@armanbilge Has pointed me in the direction of Channel as the primitive type I may be after.
Channel certainly appears in the API reference, but it might be nice to briefly mention it in the main docs - possibly next to Topic?
When this graduates to docs, here's a popular recipe! by @SystemFw in https://discord.com/channels/632277896739946517/632310980449402880/1068281893549789195
val prog =
Channel
.bounded[IO, String](10)
.flatMap { ch =>
val producer = ch.send("first")
val consumer = ch.stream.evalMap(IO.println).compile.drain
def gracefulClosure(f: FiberIO[Unit]) =
ch.close >> f.join.void.timeoutTo(5.seconds, f.cancel)
producer >>
Resource.make(consumer.start)(gracefulClosure).use_
}