本文整理了Java中io.reactivex.Single.doOnDispose()
方法的一些代码示例,展示了Single.doOnDispose()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Single.doOnDispose()
方法的具体详情如下:
包路径:io.reactivex.Single
类名称:Single
方法名:doOnDispose
[英]Calls the shared Action if a SingleObserver subscribed to the current Single disposes the common Disposable it received via onSubscribe. Scheduler: doOnDispose does not operate by default on a particular Scheduler.
[中]如果订阅当前单曲的SingleObserver处理了通过onSubscribe接收到的公用一次性操作,则调用共享操作。调度器:默认情况下,doOnDispose不会在特定的调度器上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Object> apply(Single<Object> s) throws Exception {
return s.doOnDispose(Functions.EMPTY_ACTION);
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void doOnDisposeNull() {
just1.doOnDispose(null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void doOnDispose() {
final int[] count = { 0 };
Single.never().doOnDispose(new Action() {
@Override
public void run() throws Exception {
count[0]++;
}
}).test(true);
assertEquals(1, count[0]);
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void noDisposeOnAllSuccess2() {
final AtomicInteger counter = new AtomicInteger();
Single<Integer> source = Single.just(1).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
Single.zip(Arrays.asList(source, source), new Function<Object[], Object>() {
@Override
public Integer apply(Object[] o) throws Exception {
return (Integer)o[0] + (Integer)o[1];
}
})
.test()
.assertResult(2);
assertEquals(0, counter.get());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void noDisposeOnAllSuccess() {
final AtomicInteger counter = new AtomicInteger();
Single<Integer> source = Single.just(1).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
Single.zip(source, source, new BiFunction<Integer, Integer, Object>() {
@Override
public Integer apply(Integer a, Integer b) throws Exception {
return a + b;
}
})
.test()
.assertResult(2);
assertEquals(0, counter.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void doOnDisposeDispose() {
final int[] calls = { 0 };
TestHelper.checkDisposed(PublishSubject.create().singleOrError().doOnDispose(new Action() {
@Override
public void run() throws Exception {
calls[0]++;
}
}));
assertEquals(1, calls[0]);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void doOnDisposeSuccess() {
final int[] calls = { 0 };
Single.just(1)
.doOnDispose(new Action() {
@Override
public void run() throws Exception {
calls[0]++;
}
})
.test()
.assertResult(1);
assertEquals(0, calls[0]);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void flatMapPublisherCancelDuringSingle() {
final AtomicBoolean disposed = new AtomicBoolean();
TestSubscriber<Integer> ts = Single.<Integer>never()
.doOnDispose(new Action() {
@Override
public void run() throws Exception {
disposed.set(true);
}
})
.flatMapPublisher(new Function<Integer, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(Integer v) throws Exception {
return Flowable.range(v, 5);
}
})
.test()
.assertNoValues()
.assertNotTerminated();
assertFalse(disposed.get());
ts.cancel();
assertTrue(disposed.get());
ts.assertNotTerminated();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalSuccessDoesntDisposeMain() {
final int[] calls = { 0 };
Single.just(1)
.doOnDispose(new Action() {
@Override
public void run() throws Exception {
calls[0]++;
}
})
.timeout(1, TimeUnit.DAYS)
.test()
.assertResult(1);
assertEquals(0, calls[0]);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void doOnDisposeError() {
final int[] calls = { 0 };
Single.error(new TestException())
.doOnDispose(new Action() {
@Override
public void run() throws Exception {
calls[0]++;
}
})
.test()
.assertFailure(TestException.class);
assertEquals(0, calls[0]);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void doOnDisposeCrash() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
PublishSubject<Integer> ps = PublishSubject.create();
ps.singleOrError().doOnDispose(new Action() {
@Override
public void run() throws Exception {
throw new TestException();
}
})
.test()
.cancel();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
代码示例来源:origin: hzsweers/blackmirror
.doOnDispose(new Action() {
@Override public void run() {
dialog.cancel();
代码示例来源:origin: quanturium/bouquet
.doOnDispose(() -> {
if (getScope() == RxLogger.Scope.ALL || getScope() == RxLogger.Scope.LIFECYCLE)
getMessageManager().printEvent(getComponentInfo(), RxEvent.DISPOSE);
内容来源于网络,如有侵权,请联系作者删除!