rx.Single.create()方法的使用及代码示例

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

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

Single.create介绍

暂无

代码示例

代码示例来源:origin: apollographql/apollo-android

/**
 * Converts an {@link ApolloStoreOperation} to a Single.
 *
 * @param operation the ApolloStoreOperation to convert
 * @param <T>       the value type
 * @return the converted Single
 */
@NotNull public static <T> Single<T> from(@NotNull final ApolloStoreOperation<T> operation) {
 checkNotNull(operation, "operation == null");
 return Single.create(new Single.OnSubscribe<T>() {
  @Override
  public void call(final SingleSubscriber<? super T> subscriber) {
   operation.enqueue(new ApolloStoreOperation.Callback<T>() {
    @Override public void onSuccess(T result) {
     subscriber.onSuccess(result);
    }
    @Override public void onFailure(Throwable t) {
     subscriber.onError(t);
    }
   });
  }
 });
}

代码示例来源:origin: AsyncHttpClient/async-http-client

/**
 * Emits the results of {@code AsyncHandlers} obtained from
 * {@code handlerSupplier} for HTTP requests obtained obtained by calling
 * {@code requestTemplate}.
 *
 * @param requestTemplate called to start the HTTP request with an
 *                        {@code AysncHandler} that builds the HTTP response and
 *                        propagates results to the returned {@code Single}.  The
 *                        {@code Future} that is returned by {@code requestTemplate}
 *                        will be used to cancel the request when the {@code Single} is
 *                        unsubscribed.
 * @param handlerSupplier supplies the desired {@code AsyncHandler}
 *                        instances that are used to produce results
 * @return a {@code Single} that executes new requests on subscription by
 * calling {@code requestTemplate} and that emits the results
 * produced by the {@code AsyncHandlers} supplied by
 * {@code handlerSupplier}
 * @throws NullPointerException if at least one of the parameters is
 *                              {@code null}
 */
public static <T> Single<T> create(Func1<? super AsyncHandler<?>, ? extends Future<?>> requestTemplate,
                  Func0<? extends AsyncHandler<? extends T>> handlerSupplier) {
 requireNonNull(requestTemplate);
 requireNonNull(handlerSupplier);
 return Single.create(subscriber -> {
  final AsyncHandler<?> bridge = createBridge(subscriber, handlerSupplier.call());
  final Future<?> responseFuture = requestTemplate.call(bridge);
  subscriber.add(Subscriptions.from(responseFuture));
 });
}

代码示例来源:origin: Netflix/EVCache

public Single<T> observe() {
  return Single.create(subscriber ->
    addListener((EVCacheGetOperationListener<T>) future -> {
      try {
        subscriber.onSuccess(get());
      } catch (Throwable e) {
        subscriber.onError(e);
      }
    })
  );
}

代码示例来源:origin: Netflix/EVCache

public Single<Map<String, T>> observe() {
  return Single.create(subscriber ->
    addListener(future -> {
      try {
        subscriber.onSuccess(get());
      } catch (Throwable e) {
        subscriber.onError(e);
      }
    })
  );
}

代码示例来源:origin: Netflix/EVCache

public Single<Map<String, T>> getSome(long to, TimeUnit units, boolean throwException, boolean hasZF, Scheduler scheduler) {
  final Stopwatch operationDuration = EVCacheMetricsFactory.getStatsTimer(appName, serverGroup, metricName).start();
  return observe().timeout(to, units, Single.create(subscriber -> {
    try {
      final Collection<Operation> timedoutOps = new HashSet<Operation>();

代码示例来源:origin: Netflix/EVCache

public Single<T> get(long duration, TimeUnit units, boolean throwException, boolean hasZF, Scheduler scheduler) {
  return observe().timeout(duration, units, Single.create(subscriber -> {
    // whenever timeout occurs, continuous timeout counter will increase by 1.
    MemcachedConnection.opTimedOut(op);
    if (op != null) op.timeOut();
    if (!hasZF) EVCacheMetricsFactory.getCounter(appName, null, serverGroup.getName(), appName + "-get-CheckedOperationTimeout", DataSourceType.COUNTER).increment();
    if (throwException) {
      subscriber.onError(new CheckedOperationTimeoutException("Timed out waiting for operation", op));
    } else {
      if (isCancelled()) {
        if (hasZF) EVCacheMetricsFactory.getCounter(appName, null, serverGroup.getName(), appName + "-get-Cancelled", DataSourceType.COUNTER).increment();
      }
      subscriber.onSuccess(objRef.get());
    }
  }), scheduler).doAfterTerminate(new Action0() {
    @Override
    public void call() {
      
    }
  }
  );
}

代码示例来源:origin: akarnokd/RxJava2Interop

/**
 * Converts an 2.x SingleSource (the base type of 2.x Single) into a
 * 1.x Single, composing cancellation (unsubscription) through.
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
 * </dl>
 * @param <T> the value type
 * @param source the source 2.x SingleSource instance, not null
 * @return the new 1.x Single instance
 * @throws NullPointerException if {@code source} is null
 */
@io.reactivex.annotations.SchedulerSupport(io.reactivex.annotations.SchedulerSupport.NONE)
public static <T> rx.Single<T> toV1Single(io.reactivex.SingleSource<T> source) {
  io.reactivex.internal.functions.ObjectHelper.requireNonNull(source, "source is null");
  return rx.Single.create(new SingleV2ToSingleV1<T>(source));
}

代码示例来源:origin: akarnokd/RxJava2Interop

/**
 * Converts an 2.x MaybeSource (the base type of 2.x Maybe) into a
 * 1.x Single, composing cancellation (unsubscription) through and
 * signalling NoSuchElementException if the MaybeSource is empty.
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
 * </dl>
 * @param <T> the source's value type
 * @param source the source 2.x MaybeSource instance, not null
 * @return the new 1.x Single instance
 * @throws NullPointerException if {@code source} is null
 */
@io.reactivex.annotations.SchedulerSupport(io.reactivex.annotations.SchedulerSupport.NONE)
public static <T> rx.Single<T> toV1Single(io.reactivex.MaybeSource<T> source) {
  io.reactivex.internal.functions.ObjectHelper.requireNonNull(source, "source is null");
  return rx.Single.create(new MaybeV2ToSingleV1<T>(source));
}

代码示例来源:origin: reactiverse/reactive-pg-client

/**
 * Get a connection from the pool.
 * @return 
 */
public Single<io.reactiverse.rxjava.pgclient.PgConnection> rxGetConnection() { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  getConnection(fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

/**
 * Like {@link io.reactiverse.rxjava.pgclient.PgTransaction#rollback} with an handler to be notified when the transaction rollback has completed
 * @return 
 */
public Single<Void> rxRollback() { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  rollback(fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxQuery(String sql) { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  query(sql, fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql, io.reactiverse.rxjava.pgclient.Tuple arguments) { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  preparedQuery(sql, arguments, fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedBatch(String sql, List<io.reactiverse.rxjava.pgclient.Tuple> batch) { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  preparedBatch(sql, batch, fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

/**
 * Connect the subscriber to Postgres.
 * @return a reference to this, so the API can be used fluently
 */
public Single<Void> rxConnect() { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  connect(fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

/**
 * Like {@link io.reactiverse.rxjava.pgclient.PgClient#connect} with options build from the environment variables.
 * @param vertx 
 * @return 
 */
public static Single<io.reactiverse.rxjava.pgclient.PgConnection> rxConnect(io.vertx.rxjava.core.Vertx vertx) { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  connect(vertx, fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

/**
 * Prepare and execute a query.
 * @param sql the prepared query SQL
 * @return a reference to this, so the API can be used fluently
 */
public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql) { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  preparedQuery(sql, fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

/**
 * Prepare and execute a query.
 * @param sql the prepared query SQL
 * @param arguments the list of arguments
 * @return a reference to this, so the API can be used fluently
 */
public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql, io.reactiverse.rxjava.pgclient.Tuple arguments) { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  preparedQuery(sql, arguments, fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

/**
 * Create a prepared query.
 * @param sql the sql
 * @return 
 */
public Single<io.reactiverse.rxjava.pgclient.PgPreparedQuery> rxPrepare(String sql) { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  prepare(sql, fut);
 }));
}

代码示例来源:origin: reactiverse/reactive-pg-client

public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql, io.reactiverse.rxjava.pgclient.Tuple arguments) { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  preparedQuery(sql, arguments, fut);
 }));
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Block the given address for the given multicast address and notifies the  once
 * the operation completes.
 * @param multicastAddress the address for which you want to block the source address
 * @param sourceToBlock the source address which should be blocked. You will not receive an multicast packets for it anymore.
 * @return a reference to this, so the API can be used fluently
 */
public Single<io.vertx.rxjava.core.datagram.DatagramSocket> rxBlockMulticastGroup(String multicastAddress, String sourceToBlock) { 
 return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> {
  blockMulticastGroup(multicastAddress, sourceToBlock, fut);
 }));
}

相关文章