0

I'm trying to compose ZIO.fromFuture with ZStream.async following this example but I have a type issue: ZIO.fromFuture gives me Task[+A] = ZIO[Any, Throwable, A] but Zstream.emit needs ZIO[R, Option[E], Chunk[A]]

[Option[Throwable] vs Throwable2

How could I turn a Future into a ZStream if that makes sense?

    val t: ZIO[Any, Throwable, Chunk[A]] = ZIO.fromFuture(_ => Future[A])
    val stream = ZStream.async[Any, Throwable, A] { cb =>
      cb(t)
      None
    }
Bill'o
  • 514
  • 1
  • 5
  • 19
  • The example you point at is for callback specific semantic. What's your goal? If your future gives you a single `A`, why put it in a stream? – Gaël J Feb 15 '23 at 09:16
  • indeed but ain't a stream ZStream[R, E, O] a description of a program that, when evaluated, may emit zero or more values of type O? Not sure I am following, how to implement that in the case of a long polling http request or a websocket future based client? – Bill'o Feb 15 '23 at 10:21
  • 2
    What does your http client gives you as return type? Likely already something similar to a stream. – Gaël J Feb 15 '23 at 10:37
  • to be clearer, I am looking for something similar to Source.future(Future.successful(...)) in akka streams – Bill'o Feb 15 '23 at 10:56
  • 1
    Can You provide some more context here ? Like for example the function that returns the `Future` ? – Dominik Wosiński Feb 15 '23 at 12:13
  • 4
    In Akka Streams `Source.future()` emits only one value. The ZIO equivalent is `ZStream.fromZIO(ZIO.fromFuture())` – Gaël J Feb 15 '23 at 12:26
  • ok thanks (for reference it's just a wsClient.execute() at the end) – Bill'o Feb 15 '23 at 13:22

0 Answers0