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

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

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

Future.exception介绍

[英]Creates a failed future.
[中]创造一个失败的未来。

代码示例

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

@Override
public final void onException(final Throwable ex) {
 task.cancel(false);
 becomeIfEmpty(Future.exception(ex));
}

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

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

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

@Override
public final void onException(final Throwable ex) {
 becomeIfEmpty(Future.exception(ex));
}

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

static <R> Exchange<R> fail(final Throwable ex) {
 final Future<Void> result = Future.exception(ex);
 return channel -> result.unsafeCast();
}

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

/**
  * Isolates the execution of the supplier on this future pool.
  * @param s  the supplier.
  * @return   a future with the result of the supplier.
  */
 public final <T> Future<T> async(final Supplier<T> s) {
  try {
   final AsyncPromise<T> p = new AsyncPromise<>(s);
   executor.submit(p);
   return p;
  } catch (final RejectedExecutionException ex) {
   return Future.exception(ex);
  }
 }
}

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

@Override
public final Future<Void> close() {
 closed = true;
 Promise<?> w;
 while ((w = waiters.poll()) != null) {
  waitersSemaphore.release();
  w.become(Future.exception(new RuntimeException("Pool closed")));
 }
 return drain();
}

代码示例来源: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

@Override
public final void run() {
 handler.raise(exception);
 becomeIfEmpty(Future.exception(exception));
}

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

private final <T> Future<T> execute(final Exchange<T> exchange) {
 try {
  final Future<T> run = exchange.run(channel);
  return queryTimeout.map(t -> run.within(t, scheduler)).orElse(run);
 } catch (final Throwable t) {
  NonFatalException.verify(t);
  return Future.exception(t);
 }
}

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

/**
 * Finds the first future that completes.
 *
 * @param list  futures to select from.
 * @return      a future that is satisfied with the result of the first future to
 *              complete.
 */
public static <T> Future<T> firstCompletedOf(final List<Future<T>> list) {
 switch (list.size()) {
 case 0:
  return Future.exception(new IllegalArgumentException("Can't select first completed future from empty list."));
 case 1:
  return list.get(0);
 default:
  final FirstCompletedOfPromise<T> p = new FirstCompletedOfPromise<>(list);
  for (final Future<T> f : list) {
   if (f instanceof SatisfiedFuture)
    return f;
   f.respond(p);
  }
  return p;
 }
}

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

private final <T> Future<T> execute(final Exchange<T> exchange) {
 try {
  final Future<T> run = exchange.run(channel);
  return queryTimeout.map(t -> run.within(t, scheduler)).orElse(run);
 } catch (final Throwable t) {
  NonFatalException.verify(t);
  return Future.exception(t);
 }
}

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

default public Exchange<T> onFailure(final Function<Throwable, Exchange<?>> e) {
 return channel -> run(channel).rescue(ex -> e.apply(ex).run(channel).flatMap(v -> Future.exception(ex)));
}

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

return p;
 } else
  return Future.exception(new IllegalStateException("Previous `receive` still pending."));
});

代码示例来源: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;
 }
}

相关文章