-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move j.u.c.Flow
interop methods onto Stream
#3346
Move j.u.c.Flow
interop methods onto Stream
#3346
Conversation
subscription.run | ||
): Stream[F, Nothing] = | ||
Stream.eval(apply(stream, subscriber)).flatMap { subscription => | ||
Stream.eval(F.delay(subscriber.onSubscribe(subscription))) >> subscription.run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be exec
and ++
, shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's exec, then subscription.run
will never evaluate.
The two options are:
Stream.eval(...) >> subscription.run
Stream.exec(...) ++ subscription.run
The former felt more appropriate to me, it establishes the monadic dependence. Not sure what the subtle differences are.
/** Provides syntax for `IO` streams. */ | ||
implicit final class IOOps[A](private val self: Stream[IO, A]) extends AnyVal { | ||
|
||
/** Creates a [[Publisher]] from this [[Stream]]. | ||
* | ||
* The stream is only ran when elements are requested. | ||
* | ||
* @note This [[Publisher]] can be reused for multiple [[Subscribers]], | ||
* each [[Subscription]] will re-run the [[Stream]] from the beginning. | ||
* | ||
* @see [[toPublisher]] for a safe version that returns a [[Stream]]. | ||
*/ | ||
def unsafeToPublisher()(implicit | ||
runtime: IORuntime | ||
): Publisher[A] = | ||
interop.flow.unsafeToPublisher(self) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the one I'm most interested in. It is the Stream
analog of io.unsafeToFuture()
.
The motivation is to facilitate interop with other libraries e.g. raquo/Airstream#114:
EventStream.fromPublisher(fs2Stream.unsafeToPublisher())
A couple of random thoughts against this:
A couple of random thoughts in favor of this:
|
I think those are really good points, which is why I asked Luis to post them here. I think a reasonable compromise could be to keep |
So that it Just Works™️ without the annoying
import fs2.interop.flow.syntax._
, which is now deprecated. cc @BalmungSan