本文整理汇总了Java中io.reactivex.disposables.Disposable.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java Disposable.dispose方法的具体用法?Java Disposable.dispose怎么用?Java Disposable.dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.disposables.Disposable
的用法示例。
在下文中一共展示了Disposable.dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test0
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Override
public void test0() {
Log.i(TAG, "test0() Interval simple demo");
final Disposable disposable = Observable.interval(1, TimeUnit.SECONDS, Schedulers.computation())
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
Log.d(TAG, "Consumer<String> accept() aLong: " + aLong);
}
});
// sleep 3 seconds
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// dispose
Log.d(TAG, "test0() disposable.dispose()");
disposable.dispose();
}
示例2: workerDispose
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void workerDispose() throws Exception {
Task t = new Task(1);
Worker w = SwingSchedulers.edt().createWorker();
try {
Disposable d = w.schedule(t, 500, TimeUnit.MILLISECONDS);
Thread.sleep(100);
d.dispose();
Thread.sleep(500);
Assert.assertEquals(0, t.calls);
} finally {
w.dispose();
}
}
示例3: main
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
public static void main(String[] args) {
Disposable d = Observable.interval(1, TimeUnit.SECONDS)
.doOnDispose(() -> System.out.println("Disposing on thread"
+ Thread.currentThread().getName()))
.subscribe(i -> System.out.println("Received " +
i));
sleep(3000);
d.dispose();
sleep(3000);
}
示例4: main
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> seconds =
Observable.interval(1, TimeUnit.SECONDS);
Disposable disposable =
seconds.subscribe(l -> System.out.println("Received: " + l));
//sleep 5 seconds
sleep(5000);
//dispose and stop emissions
disposable.dispose();
//sleep 5 seconds to prove
//there are no more emissions
sleep(5000);
}
示例5: directScheduleOnceDisposedDoesNotRun
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void directScheduleOnceDisposedDoesNotRun() {
CountingRunnable counter = new CountingRunnable();
Disposable disposable = scheduler.scheduleDirect(counter);
disposable.dispose();
runUiThreadTasks();
assertEquals(0, counter.get());
}
示例6: directScheduleOnceWithDelayDisposedDoesNotRun
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void directScheduleOnceWithDelayDisposedDoesNotRun() {
CountingRunnable counter = new CountingRunnable();
Disposable disposable = scheduler.scheduleDirect(counter, 1, MINUTES);
idleMainLooper(30, SECONDS);
disposable.dispose();
idleMainLooper(30, SECONDS);
runUiThreadTasks();
assertEquals(0, counter.get());
}
示例7: workerScheduleOnceDisposedDoesNotRun
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void workerScheduleOnceDisposedDoesNotRun() {
Worker worker = scheduler.createWorker();
CountingRunnable counter = new CountingRunnable();
Disposable disposable = worker.schedule(counter);
disposable.dispose();
runUiThreadTasks();
assertEquals(0, counter.get());
}
示例8: test0
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Override
public void test0() {
Log.i(TAG, "test0() Debounce simple demo, interval(100, TimeUnit.MILLISECONDS).debounce(100, TimeUnit.MILLISECONDS)");
Disposable disposable = Observable.interval(100, TimeUnit.MILLISECONDS)
.debounce(100, TimeUnit.MILLISECONDS)
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long l) throws Exception {
Log.d(TAG, "Consumer<Long> accept() l: " + l);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Log.d(TAG, "Consumer<Throwable> accept() throwable: " + throwable);
}
}, new Action() {
@Override
public void run() throws Exception {
Log.d(TAG, "Action run() for onComplete()");
}
});
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// dispose
Log.d(TAG, "test0() disposable.dispose()");
disposable.dispose();
}
示例9: bind
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void bind() throws Exception {
ObservableList<String> origList = RxCollections.of(new ArrayList<>());
javafx.collections.ObservableList<String> fxList = FXCollections.observableList(new ArrayList<>());
Disposable listBinding = RxCollectionsFX.bind(origList, fxList);
String str = "Hello world!";
origList.add(str);
assertEquals(fxList.get(0), str);
listBinding.dispose();
}
示例10: detachView
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Override
public void detachView() {
for (Disposable disposable : disposables) {
if (!disposable.isDisposed()) disposable.dispose();
}
mView = null;
}
示例11: clearQueue
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
public void clearQueue() {
Log.d(TAG, "clearQueue: size to be cleared=" + mLoadingDetections.size());
// For each of the loading detections dispose it and remove it. Fuck em off
Iterator<Map.Entry<String, Disposable>> iterator = mLoadingDetections.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Disposable> entry = iterator.next();
Disposable disposable = entry.getValue();
if (!disposable.isDisposed()) {
disposable.dispose();
}
iterator.remove();
}
}
示例12: downloadProducts
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void downloadProducts() throws Exception {
String category = faker.numerify("category-##");
//insert sample data into es
List<Product> sampleProducts = IntStream.range(1, 5).mapToObj(index -> {
Product product = createProduct(category);
try {
productDao.upsertProduct(product);
} catch (InvalidProtocolBufferException e) {
log.error(" error on creating sample product for test downloadProducts", e);
}
return product;
}).collect(Collectors.toList());
esClient.admin().indices().flush(Requests.flushRequest(INDEX)).actionGet();
PublishSubject<Product> productPublishSubject = PublishSubject.create();
List<Product> downloadedProducts = Lists.newArrayList();
Disposable disposable = productPublishSubject
.doOnNext(product -> downloadedProducts.add(product))
.doOnError(t -> fail("should not failed", t))
.doOnComplete(() -> {
Product[] downloadedProductArray = sampleProducts.toArray(new Product[]{});
assertThat(downloadedProducts).containsOnly(downloadedProductArray);
})
.subscribe();
productDao.downloadProducts(
DownloadProductsRequest.newBuilder()
.setCategory(category)
.build(),
productPublishSubject
);
disposable.dispose();
}
示例13: testHotObservable
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void testHotObservable() throws Exception {
ConnectableObservable<Long> connectableObservable = Observable.interval(1,
TimeUnit.SECONDS,
Schedulers.from(executorService)).publish();
connectableObservable.subscribe(x -> System.out.println("L1:" + x));
Thread.sleep(2000);
Disposable disposable = connectableObservable.connect(); //Let us begin
connectableObservable.subscribe(x -> System.out.println("L2:" + x));
Thread.sleep(2000);
connectableObservable.subscribe(x -> System.out.println("L3:" + x));
disposable.dispose();
Thread.sleep(10000);
}
示例14: testSceneLifecycleMultiObserver
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void testSceneLifecycleMultiObserver() throws Exception {
stage.start();
Scene scene = new DumpScene();
stage.pushScene(scene);
Observable<Integer> lifecycle = SceneLifecycle.create(scene);
RecordConsumer consumer1 = new RecordConsumer();
Disposable disposable1 = lifecycle.subscribe(consumer1);
SceneCalling calling1 = new SceneCalling();
calling1.onCreate++;
calling1.onCreateView++;
calling1.onAttachView++;
calling1.onStart++;
consumer1.assertSceneCalling(calling1);
stage.resume();
calling1.onResume++;
consumer1.assertSceneCalling(calling1);
RecordConsumer consumer2 = new RecordConsumer();
Disposable disposable2 = lifecycle.subscribe(consumer2);
SceneCalling calling2 = new SceneCalling();
calling2.onCreate++;
calling2.onCreateView++;
calling2.onAttachView++;
calling2.onStart++;
calling2.onResume++;
consumer2.assertSceneCalling(calling2);
stage.pause();
calling1.onPause++;
consumer1.assertSceneCalling(calling1);
calling2.onPause++;
consumer2.assertSceneCalling(calling2);
assertFalse(disposable1.isDisposed());
disposable1.dispose();
assertTrue(disposable1.isDisposed());
stage.resume();
consumer1.assertSceneCalling(calling1);
calling2.onResume++;
consumer2.assertSceneCalling(calling2);
assertFalse(disposable2.isDisposed());
disposable2.dispose();
assertTrue(disposable2.isDisposed());
stage.pause();
consumer1.assertSceneCalling(calling1);
consumer2.assertSceneCalling(calling2);
}
示例15: testThrashSubscriptions
import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void testThrashSubscriptions() throws InterruptedException, ExecutionException
{
final AtomicInteger globalCounter = new AtomicInteger(0);
final int subscriberCount = 25;
ExecutorService executorService = Executors.newFixedThreadPool(subscriberCount);
for (int j = 0; j < subscriberCount; ++j) {
System.gc();
final AtomicInteger counter = new AtomicInteger(0);
final Flowable<Integer> valueObservable = source.get("test");
final Callable<Disposable> queryCallable = new Callable<Disposable>() {
final int index = globalCounter.incrementAndGet();
@Override
public Disposable call() throws Exception
{
return valueObservable.subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer)
{
counter.incrementAndGet();
}
});
}
};
List<Callable<Disposable>> callables = new ArrayList<>();
for (int i = 0; i < subscriberCount; ++i) {
callables.add(queryCallable);
}
List<Future<Disposable>> futures = executorService.invokeAll(callables);
List<Disposable> subscriptions = new ArrayList<>();
for (int i = 0; i < subscriberCount; ++i) {
subscriptions.add(futures.get(i).get());
}
source.onNext("test", 1);
for (int i = 0; i < 10; ++i) {
if (counter.get() != subscriberCount) {
Thread.sleep(10);
}
}
assertEquals(subscriberCount, counter.get());
for (int i = 0; i < subscriberCount; ++i) {
Disposable subscription = subscriptions.get(i);
subscription.dispose();
}
}
}