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

1.x: enable backpressure with from(Future). #3893

Merged
merged 1 commit into from
Apr 29, 2016
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 @@ -22,6 +22,7 @@
import rx.exceptions.Exceptions;
import rx.Subscriber;
import rx.functions.Action0;
import rx.internal.producers.SingleProducer;
import rx.subscriptions.Subscriptions;

/**
Expand Down Expand Up @@ -72,8 +73,7 @@ public void call() {
return;
}
T value = (unit == null) ? (T) that.get() : (T) that.get(time, unit);
subscriber.onNext(value);
subscriber.onCompleted();
subscriber.setProducer(new SingleProducer<T>(subscriber, value));
} catch (Throwable e) {
// If this Observable is unsubscribed, we will receive an CancellationException.
// However, CancellationException will not be passed to the final Subscriber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,16 @@
package rx.internal.operators;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.Test;

import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.observers.TestObserver;
import rx.observers.TestSubscriber;
import rx.*;
import rx.observers.*;
import rx.schedulers.Schedulers;

public class OnSubscribeToObservableFutureTest {
Expand Down Expand Up @@ -139,4 +128,28 @@ public Object get(long timeout, TimeUnit unit) throws InterruptedException, Exec
assertEquals(0, testSubscriber.getOnCompletedEvents().size());
assertEquals(0, testSubscriber.getOnNextEvents().size());
}

@Test
public void backpressure() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0);

FutureTask<Integer> f = new FutureTask<Integer>(new Runnable() {
@Override
public void run() {

}
}, 1);

f.run();

Observable.from(f).subscribe(ts);

ts.assertNoValues();

ts.requestMore(1);

ts.assertValue(1);
ts.assertNoErrors();
ts.assertCompleted();
}
}