Skip to content

Fixed an issue in JSON-RPC event stream services (none exist yet) where retries excluded the initial-request event. #2673

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

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
public class AsyncStreamPrepender<T> implements Publisher<T> {
private final Publisher<T> delegate;
private final T firstItem;
private Subscriber<? super T> subscriber;
private volatile boolean complete = false;
private volatile boolean firstRequest = true;

public AsyncStreamPrepender(Publisher<T> delegate, T firstItem) {
this.delegate = delegate;
Expand All @@ -36,11 +33,18 @@ public AsyncStreamPrepender(Publisher<T> delegate, T firstItem) {

@Override
public void subscribe(Subscriber<? super T> s) {
subscriber = s;
delegate.subscribe(new DelegateSubscriber());
delegate.subscribe(new DelegateSubscriber(s));
}

private class DelegateSubscriber implements Subscriber<T> {
private final Subscriber<? super T> subscriber;
private volatile boolean complete = false;
private volatile boolean firstRequest = true;

private DelegateSubscriber(Subscriber<? super T> subscriber) {
this.subscriber = subscriber;
}

@Override
public void onSubscribe(Subscription subscription) {
subscriber.onSubscribe(new Subscription() {
Expand Down Expand Up @@ -90,7 +94,6 @@ public void request(long n) {
public void cancel() {
cancelled = true;
subscription.cancel();
subscriber = null;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ public void sequence() {
}
}

@Test
public void multiSubscribe_stillPrepends() {
AsyncStreamPrepender<Long> prepender = new AsyncStreamPrepender<>(rangeLong(1L, 5L), 0L);
Flowable<Long> prepended1 = fromPublisher(prepender);
Flowable<Long> prepended2 = fromPublisher(prepender);

Iterator<Long> iterator1 = prepended1.blockingIterable(1).iterator();
Iterator<Long> iterator2 = prepended2.blockingIterable(1).iterator();

for (long i = 0; i <= 5; i++) {
assertEquals(i, iterator1.next().longValue());
assertEquals(i, iterator2.next().longValue());
}
}

@Test
public void error() {
Flowable<Long> error = Flowable.error(IllegalStateException::new);
Expand Down