scala.concurrent.Promise.future()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(281)

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

Promise.future介绍

暂无

代码示例

代码示例来源:origin: square/retrofit

@Override public Future<Response<T>> adapt(Call<T> call) {
  Promise<Response<T>> promise = Promise.apply();

  call.enqueue(new Callback<T>() {
   @Override public void onResponse(Call<T> call, Response<T> response) {
    promise.success(response);
   }

   @Override public void onFailure(Call<T> call, Throwable t) {
    promise.failure(t);
   }
  });

  return promise.future();
 }
}

代码示例来源:origin: square/retrofit

@Override public Future<T> adapt(Call<T> call) {
  Promise<T> promise = Promise.apply();

  call.enqueue(new Callback<T>() {
   @Override public void onResponse(Call<T> call, Response<T> response) {
    if (response.isSuccessful()) {
     promise.success(response.body());
    } else {
     promise.failure(new HttpException(response));
    }
   }

   @Override public void onFailure(Call<T> call, Throwable t) {
    promise.failure(t);
   }
  });

  return promise.future();
 }
}

代码示例来源:origin: org.opendaylight.netconf/netconf-topology

@Override
  public Future<Set<SourceIdentifier>> getResolvedSources() {
    return resolvedSourcesPromise.future();
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime

public Future<ActorGateway> getActorGatewayFuture() {
    return futureActorGateway.future();
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.10

private FlinkCompletableFuture(T value) {
  promise = Promise$.MODULE$.successful(value);
  scalaFuture = promise.future();
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.10

private FlinkCompletableFuture(Throwable t) {
  promise = Promise$.MODULE$.failed(t);
  scalaFuture = promise.future();
}

代码示例来源:origin: traneio/ndbc

protected final <T> Future<T> convert(final io.trane.future.Future<T> future) {
 final Promise<T> promise = Promise$.MODULE$.apply();
 future.onSuccess(promise::success).onFailure(promise::failure);
 return promise.future();
}

代码示例来源:origin: traneio/ndbc

protected final <T> Future<T> convert(final io.trane.future.Future<T> future) {
 final Promise<T> promise = Promise$.MODULE$.apply();
 future.onSuccess(promise::success).onFailure(promise::failure);
 return promise.future();
}

代码示例来源:origin: ks-no/eventstore2

@Override
public Future<EventBatch> loadEventsForAggregateIdAsync(final String aggregateType, final String aggregateId, final String fromJournalId) {
  final Document query = new Document("rid", aggregateId);
  if (fromJournalId != null)
    query.append("jid", new Document("$gt", Long.parseLong(fromJournalId)));
  final ArrayList<Event> events = new ArrayList<>();
  com.mongodb.async.client.FindIterable<Document> dbObjects = MongoDbOperations.doDbOperation(() -> dbasync.getCollection(aggregateType).find(query).sort(new Document("jid", 1)).limit(eventReadLimit));
  final Promise<EventBatch> promise = Futures.promise();
  final Future<EventBatch> theFuture = promise.future();
  dbObjects.forEach(document -> events.add(deSerialize(((Binary) document.get("d")).getData())), (result, t) -> promise.success(new EventBatch(aggregateType, aggregateId, events, events.size() != eventReadLimit)));
  return theFuture;
}

代码示例来源:origin: traneio/future

@Benchmark
public String setValue() throws Exception {
 Promise<String> p = Promise.<String>apply();
 p.success(string);
 return Await.result(p.future(), inf);
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

private Connection getGoodConnection() {
 final Connection connection = Mockito.mock(Connection.class);
 Mockito.when(connection.connect()).thenReturn(new Promise.DefaultPromise<Connection>().success(connection).future());
 Mockito.when(connection.isConnected()).thenReturn(true);
 return connection;
}

代码示例来源:origin: traneio/future

@Benchmark
public Void ensurePromiseN() throws Exception {
 Promise<Void> p = Promise.<Void>apply();
 Future<Void> f = p.future();
 for (int i = 0; i < N.n; i++)
  f = f.transform(ensureF, ec);
 p.success(null);
 return Await.result(f, inf);
}

代码示例来源:origin: traneio/future

@Benchmark
public String setValueN() throws Exception {
 Promise<String> p = Promise.<String>apply();
 Future<String> f = p.future();
 for (int i = 0; i < N.n; i++)
  f = f.map(mapF, ec);
 p.success(string);
 return Await.result(f, inf);
}

代码示例来源:origin: traneio/future

@Benchmark
public String mapPromise() throws Exception {
 Promise<String> p = Promise.<String>apply();
 Future<String> f = p.future().map(mapF, ec);
 p.success(string);
 return Await.result(f, inf);
}

代码示例来源:origin: traneio/future

@Benchmark
public String mapPromiseN() throws Exception {
 Promise<String> p = Promise.<String>apply();
 Future<String> f = p.future();
 for (int i = 0; i < N.n; i++)
  f = f.map(mapF, ec);
 p.success(string);
 return Await.result(f, inf);
}

代码示例来源:origin: com.typesafe.play/play-ahc-ws-standalone

CompletionStage<StandaloneWSResponse> execute(Request request) {
  final Promise<StandaloneWSResponse> scalaPromise = scala.concurrent.Promise$.MODULE$.apply();
  AsyncCompletionHandler<Response> handler = new ResponseAsyncCompletionHandler(scalaPromise);
  try {
    asyncHttpClient.executeRequest(request, handler);
  } catch (RuntimeException exception) {
    scalaPromise.failure(exception);
  }
  Future<StandaloneWSResponse> future = scalaPromise.future();
  return FutureConverters.toJava(future);
}

代码示例来源:origin: traneio/future

@Benchmark
public String flatMapPromise() throws Exception {
 Promise<String> p = Promise.<String>apply();
 Future<String> f = p.future().flatMap(flatMapF, ec);
 p.success(string);
 return Await.result(f, inf);
}

代码示例来源:origin: com.typesafe.play/play-ahc-ws-standalone_2.12

CompletionStage<StandaloneWSResponse> execute(Request request) {
  final Promise<StandaloneWSResponse> scalaPromise = scala.concurrent.Promise$.MODULE$.apply();
  AsyncCompletionHandler<Response> handler = new ResponseAsyncCompletionHandler(scalaPromise);
  try {
    asyncHttpClient.executeRequest(request, handler);
  } catch (RuntimeException exception) {
    scalaPromise.failure(exception);
  }
  Future<StandaloneWSResponse> future = scalaPromise.future();
  return FutureConverters.toJava(future);
}

代码示例来源:origin: traneio/future

@Benchmark
public String flatMapPromiseN() throws Exception {
 Promise<String> p = Promise.<String>apply();
 Future<String> f = p.future();
 for (int i = 0; i < N.n; i++)
  f = f.flatMap(flatMapF, ec);
 p.success(string);
 return Await.result(f, inf);
}

代码示例来源:origin: traneio/future

@Benchmark
public Void ensurePromise() throws Exception {
 Promise<Void> p = Promise.<Void>apply();
 Future<Void> f = p.future().transform(ensureF, ec);
 p.success(null);
 return Await.result(f, inf);
}

相关文章