本文整理了Java中io.trane.future.Future.within()
方法的一些代码示例,展示了Future.within()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Future.within()
方法的具体详情如下:
包路径:io.trane.future.Future
类名称:Future
方法名:within
[英]Creates a future that fails with a TimeoutException if this future isn't completed within the timeout.
[中]如果此未来未在超时内完成,则创建一个失败且带有TimeoutException的未来。
代码示例来源:origin: traneio/future
/**
* Creates a future that fails with a TimeoutException if this future isn't
* completed within the timeout.
*
* @param timeout how long to wait for the result
* @param timeUnit the time unit of timeout.
* @param scheduler used to schedule an internal task after the timeout.
* @return a future that completes with the result of this future within the
* timeout, a failed future otherwise.
*/
default Future<T> within(final Duration timeout, final ScheduledExecutorService scheduler) {
return within(timeout, scheduler, TimeoutException.stackless);
}
代码示例来源: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
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
@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"));
}
}
内容来源于网络,如有侵权,请联系作者删除!