PublisherOps

fs2.interop.flow.syntax$.PublisherOps
final implicit class PublisherOps[A](publisher: Publisher[A]) extends AnyVal

Attributes

Source
syntax.scala
Graph
Supertypes
class AnyVal
trait Matchable
class Any

Members list

Value members

Concrete methods

def toStream[F[_]](chunkSize: Int)(implicit F: Async[F]): Stream[F, A]

Creates a Stream from an Publisher.

Creates a Stream from an Publisher.

Value parameters

chunkSize

setup the number of elements asked each time from the Publisher. A high number may be useful if the publisher is triggering from IO, like requesting elements from a database. A high number will also lead to more elements in memory. The stream will not emit new element until, either the Chunk is filled or the publisher finishes.

Attributes

Example
scala> import cats.effect.IO
scala> import fs2.Stream
scala> import fs2.interop.flow.syntax._
scala> import java.util.concurrent.Flow.Publisher
scala>
scala> def getThirdPartyPublisher(): Publisher[Int] = ???
scala>
scala> // Interop with the third party library.
scala> Stream.eval(IO.delay(getThirdPartyPublisher())).flatMap { publisher =>
    |   publisher.toStream[IO](chunkSize = 16)
    | }
res0: Stream[IO, Int] = Stream(..)
Source
syntax.scala