From e432edf7efbd05787743d1b99cd1cdec42db09e5 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 20 Jan 2024 19:46:34 +0000 Subject: [PATCH] Document `fromPublisher` + how to interop with FS2 --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 29fc28bf..28d206ba 100644 --- a/README.md +++ b/README.md @@ -432,12 +432,21 @@ If you have an `Observable[Future[A]]`, you can flatten it into `Observable[A]` A failed future results in an error (see [Error Handling](#error-handling)). +#### Creating Observables from other Streaming APIs + +`EventStream.fromPublisher[A]` creates a stream that subscribes to a Reactive Streams [Publisher](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/Flow.Publisher.html) and emits the values that it produces. + +`Publisher` is a common interface that is useful for interoperating between streaming APIs. For example, you can transform an [FS2](https://fs2.io/) `Stream[IO, A]` into an `EventStream[A]`. + +```scala +import cats.effect.unsafe.implicits._ // implicit IORuntime +EventStream.fromPublisher(fs2Stream.unsafeToPublisher()) +``` #### `EventStream.fromJsPromise` and `Signal.fromJsPromise` Behave the same as `fromFuture` above, but accept `js.Promise` instead. Useful for integration with JS libraries and APIs. - #### `EventStream.fromSeq` ```scala