com.google.common.util.concurrent.AbstractFuture.done()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(3.0k)|赞(0)|评价(0)|浏览(162)

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

AbstractFuture.done介绍

[英]Callback method that is called immediately after the future is completed.

This is called exactly once, after all listeners have executed. By default it does nothing.
[中]在将来完成后立即调用的回调方法。
在所有侦听器执行之后,此函数只调用一次。默认情况下,它什么也不做。

代码示例

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * Subclasses should invoke this method to mark the future as cancelled.
 * This will set the state of the future to {@link
 * AbstractFuture.Sync#CANCELLED} and call {@link #done()} if the state was
 * successfully changed.
 *
 * @return true if the state was successfully changed.
 */
protected final boolean cancel() {
 boolean result = sync.cancel();
 if (result) {
  done();
 }
 return result;
}

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * Subclasses should invoke this method to set the result of the computation
 * to {@code value}.  This will set the state of the future to
 * {@link AbstractFuture.Sync#COMPLETED} and call {@link #done()} if the
 * state was successfully changed.
 *
 * @param value the value that was the result of the task.
 * @return true if the state was successfully changed.
 */
protected boolean set(@Nullable V value) {
 boolean result = sync.set(value);
 if (result) {
  done();
 }
 return result;
}

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * Subclasses should invoke this method to set the result of the computation
 * to an error, {@code throwable}.  This will set the state of the future to
 * {@link AbstractFuture.Sync#COMPLETED} and call {@link #done()} if the
 * state was successfully changed.
 *
 * @param throwable the exception that the task failed with.
 * @return true if the state was successfully changed.
 * @throws Error if the throwable was an {@link Error}.
 */
protected boolean setException(Throwable throwable) {
 boolean result = sync.setException(checkNotNull(throwable));
 if (result) {
  done();
 }
 // If it's an Error, we want to make sure it reaches the top of the
 // call stack, so we rethrow it.
 if (throwable instanceof Error) {
  throw (Error) throwable;
 }
 return result;
}

代码示例来源:origin: com.diffplug.guava/guava-concurrent

/** Unblocks all threads and runs all listeners. */
private void complete() {
  for (Waiter currentWaiter = clearWaiters(); currentWaiter != null; currentWaiter = currentWaiter.next) {
    currentWaiter.unpark();
  }
  // We need to reverse the list to handle buggy listeners that depend on ordering.
  Listener currentListener = clearListeners();
  Listener reversedList = null;
  while (currentListener != null) {
    Listener tmp = currentListener;
    currentListener = currentListener.next;
    tmp.next = reversedList;
    reversedList = tmp;
  }
  for (; reversedList != null; reversedList = reversedList.next) {
    executeListener(reversedList.task, reversedList.executor);
  }
  // We call this after the listeners on the theory that done() will only be used for 'cleanup'
  // oriented tasks (e.g. clearing fields) and so can wait behind listeners which may be executing
  // more important work.  A counter argument would be that done() is trusted code and therefore
  // it would be safe to run before potentially slow or poorly behaved listeners.  Reevaluate this
  // once we have more examples of done() implementations.
  done();
}

相关文章