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

Wrapping RS Elements using lazyBuilders - You can't use Subscribers/Processors more than once #106

Open
hutchig opened this issue Nov 14, 2018 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@hutchig
Copy link
Member

hutchig commented Nov 14, 2018

In issue #105 in this comment @jroper discussed the problem: As subscribers
are single use - what do we do if we have a Graph that imports a Subscriber (or Processor) and then we try to run/materialize it more than once? For example, if that Subscriber object got a onComplete() call - which 'run' would it be for?

The obvious answer is to: instead of importing a Subscriber instance we import a means of getting
a Subscriber (and similarly for Processor/Publisher in order to keep the API consistent). Java has a pattern for this, a Supplier. Of course we have a means to produce a Subscriber in the API already the SubscriberBuilder. So we probably want one of these that will attempt to supply a 'fresh' Subscriber each time it is run/materialized, perhaps a `lazy' SubscriberBuilder or as James termed it

SubscriberBuilder ReactiveStreams.lazySubscriberBuilder(Supplier<SubscriberBuilder>)
@hutchig hutchig added this to the 1.1 milestone Nov 14, 2018
@hutchig hutchig added the enhancement New feature or request label Nov 14, 2018
@hutchig
Copy link
Member Author

hutchig commented Nov 14, 2018

The proposal to create a lazySubscriberBuilder that creates a usable Subscriber (i.e. one that is in the state 'has-never-been-subscribed-to-a-publisher') on build sort of suggests that we are
specifying that SubscriberBuilder.build (which returns a CompletionSubscriber subclass of Subscriber) does one or more of:

1 - is only valid to call once OR
2 - if it is called a second and subsequent time it returns the same CompletionSubscriber as a cached result without doing any additional method calls on any wrapped elements in the Graph's Stages.
3 - ~~ if it is re-run then the materialization can guarrantee that all parts of the Graph can
be re-materialized independantly. ~~ Plainly - this guarantee cannot be made - when, for example, there may be a ProcessorStage in the Graph created from ProcessorBuilder<T, S> via(Processor<? super R, ? extends S> processor); and the Engine knows nothing about the processor (apart from the fact it is NOT reusable).

I suggest that we document (in 1.0) that the result of materializing a stream more than once is undefined.

@hutchig hutchig changed the title Wrapping RS Elements - You can't use Subscribers/Processors more than once Wrapping RS Elements using lazyBuilders - You can't use Subscribers/Processors more than once Nov 20, 2018
@Emily-Jiang Emily-Jiang modified the milestones: 1.1, 2.0 Jun 24, 2020
@Emily-Jiang
Copy link
Member

We can think of a good use case.

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

No branches or pull requests

2 participants