fs2 icon indicating copy to clipboard operation
fs2 copied to clipboard

Documentation: Add information about `Channel`

Open davesmith00000 opened this issue 3 years ago • 1 comments

@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?

davesmith00000 avatar Apr 02 '22 09:04 davesmith00000

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_
    }

armanbilge avatar Feb 28 '23 16:02 armanbilge