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

Single.never not singleton #2349

Merged
merged 1 commit into from Sep 10, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -228,7 +228,7 @@ static <T> Single<T> just(T item) {
* @return Single
*/
static <T> Single<T> never() {
return SingleNever.instance();
return new SingleNever<T>();
}

/**
Expand Down
Expand Up @@ -21,24 +21,16 @@
* Implementation of {@link Single} that never invokes
* {@link Subscriber#onComplete()} or
* {@link Subscriber#onError(java.lang.Throwable)}.
*
* @param <T> item type
*/
final class SingleNever extends CompletionSingle<Object> {

/**
* Singleton instance.
*/
private static final SingleNever INSTANCE = new SingleNever();
final class SingleNever<T> extends CompletionSingle<T> {

private SingleNever() {
SingleNever() {
}

@Override
public void subscribe(Subscriber<? super Object> actual) {
public void subscribe(Subscriber<? super T> actual) {
actual.onSubscribe(EmptySubscription.INSTANCE);
}

@SuppressWarnings("unchecked")
static <T> Single<T> instance() {
return (Single<T>) INSTANCE;
}
}
Expand Up @@ -157,6 +157,22 @@ public void testNever() {
assertThat(subscriber.getItems(), is(empty()));
}

@Test
public void testNeverIsNotSingleton() throws InterruptedException, TimeoutException, ExecutionException {
CompletableFuture<Void> cf1 = new CompletableFuture<>();
CompletableFuture<Void> cf2 = new CompletableFuture<>();
Single<Object> never1 = Single.never();
Single<Object> never2 = Single.never();

never1.onCancel(() -> cf1.complete(null));
never2.onCancel(() -> cf2.complete(null));
never1.cancel();

cf1.get(100, TimeUnit.MILLISECONDS);
assertThat("First Single.never should be cancelled!", cf1.isDone());
assertThat("Other Single.never should NOT be cancelled!", !cf2.isDone());
}

@Test
public void testMap() {
SingleTestSubscriber<String> subscriber = new SingleTestSubscriber<>();
Expand Down