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

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

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

Future.delayed介绍

[英]Delays the result of this future. It method doesn't take in consideration how long this future takes to be completed. It assumes the state of this future after delay, being it completed or not.
[中]延迟这一未来的结果。它不考虑这个未来需要多长时间才能完成。无论是否完成,它都假定延迟后的未来状态。

代码示例

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

/**
 * Returns a void future that is satisfied after the specified delay.
 * It's a shortcut for `Future.VOID.delayed(delay, scheduler)`
 * 
 * @param delay      for how long the future must be delayed
 * @param scheduler  a scheduler for internal tasks
 * @return           the void future that is satisfied after the delay
 */
public static Future<Void> delay(final Duration delay, ScheduledExecutorService scheduler) {
 return Future.VOID.delayed(delay, scheduler);
}

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

private final Future<Void> scheduleValidation(final Duration validationInterval,
  final ScheduledExecutorService scheduler) {
 return Future.VOID.delayed(validationInterval, scheduler).flatMap(v1 -> {
  final long start = System.currentTimeMillis();
  return validateN(items.size()).flatMap(v2 -> {
   final long next = validationInterval.toMillis() - System.currentTimeMillis() - start;
   if (next <= 0)
    return scheduleValidation(validationInterval, scheduler);
   else
    return scheduleValidation(Duration.ofMillis(next), scheduler);
  });
 });
}

相关文章