io.reactivex.Single.wrap()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(117)

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

Single.wrap介绍

[英]Wraps a SingleSource instance into a new Single instance if not already a Single instance. Scheduler: wrap does not operate by default on a particular Scheduler.
[中]如果不是单个实例,则将单个源实例包装到新的单个实例中。调度程序:默认情况下,wrap不会在特定调度程序上运行。

代码示例

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

/**
 * Transform a Single by applying a particular Transformer function to it.
 * <p>
 * <img width="640" height="612" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.compose.png" alt="">
 * <p>
 * This method operates on the Single itself whereas {@link #lift} operates on the Single's SingleObservers.
 * <p>
 * If the operator you are creating is designed to act on the individual item emitted by a Single, use
 * {@link #lift}. If your operator is designed to transform the source Single as a whole (for instance, by
 * applying a particular set of existing RxJava operators to it) use {@code compose}.
 * <dl>
 * <dt><b>Scheduler:</b></dt>
 * <dd>{@code compose} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param <R> the value type of the single returned by the transformer function
 * @param transformer the transformer function, not null
 * @return the source Single, transformed by the transformer function
 * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Implementing-Your-Own-Operators">RxJava wiki: Implementing Your Own Operators</a>
 */
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> Single<R> compose(SingleTransformer<? super T, ? extends R> transformer) {
  return wrap(((SingleTransformer<T, R>) ObjectHelper.requireNonNull(transformer, "transformer is null")).apply(this));
}

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

@Test
public void wrap() {
  assertSame(Single.never(), Single.wrap(Single.never()));
  Single.wrap(new SingleSource<Object>() {
    @Override
    public void subscribe(SingleObserver<? super Object> observer) {
      observer.onSubscribe(Disposables.empty());
      observer.onSuccess(1);
    }
  })
  .test()
  .assertResult(1);
}

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

/**
 * Transform a Single by applying a particular Transformer function to it.
 * <p>
 * This method operates on the Single itself whereas {@link #lift} operates on the Single's SingleObservers.
 * <p>
 * If the operator you are creating is designed to act on the individual item emitted by a Single, use
 * {@link #lift}. If your operator is designed to transform the source Single as a whole (for instance, by
 * applying a particular set of existing RxJava operators to it) use {@code compose}.
 * <dl>
 * <dt><b>Scheduler:</b></dt>
 * <dd>{@code compose} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param <R> the value type of the single returned by the transformer function
 * @param transformer the transformer function, not null
 * @return the source Single, transformed by the transformer function
 * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Implementing-Your-Own-Operators">RxJava wiki: Implementing Your Own Operators</a>
 */
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> Single<R> compose(SingleTransformer<? super T, ? extends R> transformer) {
  return wrap(((SingleTransformer<T, R>) ObjectHelper.requireNonNull(transformer, "transformer is null")).apply(this));
}

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

/**
 * Runs multiple SingleSources and signals the events of the first one that signals (disposing
 * the rest).
 * <p>
 * <img width="640" height="515" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.ambArray.png" alt="">
 * <dl>
 * <dt><b>Scheduler:</b></dt>
 * <dd>{@code ambArray} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * @param <T> the value type
 * @param sources the array of sources. A subscription to each source will
 *            occur in the same order as in this array.
 * @return the new Single instance
 * @since 2.0
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static <T> Single<T> ambArray(final SingleSource<? extends T>... sources) {
  if (sources.length == 0) {
    return error(SingleInternalHelper.<T>emptyThrower());
  }
  if (sources.length == 1) {
    return wrap((SingleSource<T>)sources[0]);
  }
  return RxJavaPlugins.onAssembly(new SingleAmb<T>(sources, null));
}

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

/**
 * Runs multiple Single sources and signals the events of the first one that signals (cancelling
 * the rest).
 * <dl>
 * <dt><b>Scheduler:</b></dt>
 * <dd>{@code ambArray} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * @param <T> the value type
 * @param sources the array of sources. A subscription to each source will
 *            occur in the same order as in this array.
 * @return the new Single instance
 * @since 2.0
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public static <T> Single<T> ambArray(final SingleSource<? extends T>... sources) {
  if (sources.length == 0) {
    return error(SingleInternalHelper.<T>emptyThrower());
  }
  if (sources.length == 1) {
    return wrap((SingleSource<T>)sources[0]);
  }
  return RxJavaPlugins.onAssembly(new SingleAmb<T>(sources, null));
}

相关文章

微信公众号

最新文章

更多