io.trane.future.Future.value()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(2.3k)|赞(0)|评价(0)|浏览(150)

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

Future.value介绍

[英]Creates a successful future.
[中]创造成功的未来。

代码示例

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

static <T> Exchange<T> value(final T v) {
 return channel -> Future.value(v);
}

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

private Future<Integer> loop(int i) {
 return Tailrec.apply(() -> {
  if (i > 0)
   return Future.value(i - 1).flatMap(this::loop);
  else
   return Future.value(0);
 });
}

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

@Override
public final void onValue(final T value) {
 becomeIfEmpty(Future.value(value));
}

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

@Benchmark
public Future<String> value() {
 return Future.value(string);
}

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

@Override
public final void onValue(final T value) {
 task.cancel(false);
 becomeIfEmpty(Future.value(value));
}

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

static final Future<Void> VOID = Future.value((Void) null);
static final Future<Boolean> FALSE = Future.value(false);
static final Future<Boolean> TRUE = Future.value(true);

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

@Override
public Future<T> acquire() {
 if (closed)
  return Future.exception(new RuntimeException("Pool closed"));
 else {
  final T item = items.poll();
  if (item != null)
   return Future.value(item);
  else if (sizeSemaphore.tryAcquire()) {
   final Future<T> conn = supplier.get();
   return connectionTimeout.map(t -> conn.within(t, scheduler)).orElse(conn);
  } else if (waitersSemaphore.tryAcquire()) {
   final Promise<T> p = Promise.apply();
   waiters.offer(p);
   return p;
  } else
   return Future.exception(new RuntimeException("Pool exhausted"));
 }
}

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

/**
 * Selects the index of the first satisfied future.
 *
 * @param list  the list of futures to select from
 * @return      a future with the index of the first satisfied future of the list.
 */
public static <T> Future<Integer> selectIndex(final List<Future<T>> list) {
 switch (list.size()) {
 case 0:
  return Future.exception(new IllegalArgumentException("Can't select from empty list."));
 case 1:
  return list.get(0).map(v -> 0);
 default:
  final Promise<Integer> p = Promise.apply(list);
  int i = 0;
  for (final Future<?> f : list) {
   if (f instanceof SatisfiedFuture)
    return Future.value(i);
   final int ii = i;
   f.ensure(() -> p.becomeIfEmpty(Future.value(ii)));
   i++;
  }
  return p;
 }
}

相关文章