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

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

本文整理了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

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

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

  1. @Test(expected = NullPointerException.class)
  2. public void doOnLifecycleOnDisposeNull() {
  3. just1.doOnLifecycle(new Consumer<Disposable>() {
  4. @Override
  5. public void accept(Disposable d) { }
  6. }, null);
  7. }

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

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

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

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

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

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

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

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

相关文章

Observable类方法