Skip to content
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

Add interop.flow.pipeToProcessor #3449

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

BalmungSan
Copy link
Contributor

@BalmungSan BalmungSan commented Jun 14, 2024

Convenient helper.

Roadmap:

  • safe version.
  • Scaladoc.
  • unsafe version.
  • Unit test.

): Resource[F, StreamProcessor[F, I, O]] =
for {
streamSubscriber <- Resource.eval(StreamSubscriber[F, I](chunkSize))
inputStream = streamSubscriber.stream(subscribe = F.unit)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have access to the upstream Publisher yet, so we can't do the subscribe here. So we do nothing and wait for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we do nothing and wait for it.

I'm not entirely sure I understand the waiting part. Can/should we use a Deferred here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sorry, my point is that subscribe should be something like IO(publisher.subscribe(streamSubscriber)) as you can see in the implementation of syntax.fromPublisher.
Here, however, we don't have a Publisher yet, so we don't control when we are published.

Basically, this is very similar to the fromPublisher overload that accepts a Subscriber => F[Unit], just that rather than receiving the lambda, we are just returning a raw Processor / Subscriber.

@BalmungSan BalmungSan marked this pull request as ready for review June 14, 2024 22:41
@BalmungSan BalmungSan changed the title WIP: Add interop.flow.pipeToProcessor Add interop.flow.pipeToProcessor Jun 14, 2024
* like requesting elements from a database.
* A high number will also lead to more elements in memory.
*/
def pipeToProcessor[F[_], I, O](
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add these as syntax on Pipe too :)

implicit final class PipeOps[F[_], I, O](private val self: Pipe[F, I, O]) extends AnyVal {

): Resource[F, StreamProcessor[F, I, O]] =
for {
streamSubscriber <- Resource.eval(StreamSubscriber[F, I](chunkSize))
inputStream = streamSubscriber.stream(subscribe = F.unit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we do nothing and wait for it.

I'm not entirely sure I understand the waiting part. Can/should we use a Deferred here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants