io.reactivex.Observable.doOnLifecycle()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中io.reactivex.Observable.doOnLifecycle()方法的一些代码示例,展示了Observable.doOnLifecycle()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.doOnLifecycle()方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:doOnLifecycle

Observable.doOnLifecycle介绍

[英]Calls the appropriate onXXX method (shared between all Observer) for the lifecycle events of the sequence (subscription, cancellation, requesting).

Scheduler: doOnLifecycle does not operate by default on a particular Scheduler.
[中]为序列的生命周期事件(订阅、取消、请求)调用适当的onXXX方法(在所有观察者之间共享)。
调度器:默认情况下,doOnLifecycle不会在特定的调度器上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

/**
 * Modifies the source {@code ObservableSource} so that it invokes the given action when it is subscribed from
 * its subscribers. Each subscription will result in an invocation of the given action except when the
 * source {@code ObservableSource} is reference counted, in which case the source {@code ObservableSource} will invoke
 * the given action for the first subscription.
 * <p>
 * <img width="640" height="390" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/doOnSubscribe.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code doOnSubscribe} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param onSubscribe
 *            the Consumer that gets called when an Observer subscribes to the current {@code Observable}
 * @return the source {@code ObservableSource} modified so as to call this Consumer when appropriate
 * @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a>
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<T> doOnSubscribe(Consumer<? super Disposable> onSubscribe) {
  return doOnLifecycle(onSubscribe, Functions.EMPTY_ACTION);
}

代码示例来源:origin: ReactiveX/RxJava

@Test(expected = NullPointerException.class)
public void doOnLifecycleOnDisposeNull() {
  just1.doOnLifecycle(new Consumer<Disposable>() {
    @Override
    public void accept(Disposable d) { }
  }, null);
}

代码示例来源:origin: ReactiveX/RxJava

@Test(expected = NullPointerException.class)
public void doOnLifecycleOnSubscribeNull() {
  just1.doOnLifecycle(null, Functions.EMPTY_ACTION);
}

代码示例来源:origin: redisson/redisson

/**
 * Modifies the source {@code ObservableSource} so that it invokes the given action when it is subscribed from
 * its subscribers. Each subscription will result in an invocation of the given action except when the
 * source {@code ObservableSource} is reference counted, in which case the source {@code ObservableSource} will invoke
 * the given action for the first subscription.
 * <p>
 * <img width="640" height="390" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/doOnSubscribe.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code doOnSubscribe} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param onSubscribe
 *            the Consumer that gets called when an Observer subscribes to the current {@code Observable}
 * @return the source {@code ObservableSource} modified so as to call this Consumer when appropriate
 * @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a>
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<T> doOnSubscribe(Consumer<? super Disposable> onSubscribe) {
  return doOnLifecycle(onSubscribe, Functions.EMPTY_ACTION);
}

代码示例来源:origin: ReactiveX/RxJava

/**
 * Calls the dispose {@code Action} if the downstream disposes the sequence.
 * <p>
 * The action is shared between subscriptions and thus may be called concurrently from multiple
 * threads; the action must be thread safe.
 * <p>
 * If the action throws a runtime exception, that exception is rethrown by the {@code dispose()} call,
 * sometimes as a {@code CompositeException} if there were multiple exceptions along the way.
 * <p>
 * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/doOnDispose.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code doOnDispose} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param onDispose
 *            the action that gets called when the source {@code ObservableSource}'s Disposable is disposed
 * @return the source {@code ObservableSource} modified so as to call this Action when appropriate
 * @throws NullPointerException if onDispose is null
 * @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a>
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<T> doOnDispose(Action onDispose) {
  return doOnLifecycle(Functions.emptyConsumer(), onDispose);
}

代码示例来源:origin: redisson/redisson

/**
 * Calls the dispose {@code Action} if the downstream disposes the sequence.
 * <p>
 * The action is shared between subscriptions and thus may be called concurrently from multiple
 * threads; the action must be thread safe.
 * <p>
 * If the action throws a runtime exception, that exception is rethrown by the {@code dispose()} call,
 * sometimes as a {@code CompositeException} if there were multiple exceptions along the way.
 * <p>
 * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/doOnDispose.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code doOnDispose} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param onDispose
 *            the action that gets called when the source {@code ObservableSource}'s Disposable is disposed
 * @return the source {@code ObservableSource} modified so as to call this Action when appropriate
 * @throws NullPointerException if onDispose is null
 * @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a>
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<T> doOnDispose(Action onDispose) {
  return doOnLifecycle(Functions.emptyConsumer(), onDispose);
}

相关文章

Observable类方法