FutureChain.java

net.minecraft.util.FutureChain

信息

  • 全限定名:net.minecraft.util.FutureChain
  • 类型:public class
  • 包:net.minecraft.util
  • 源码路径:src/main/java/net/minecraft/util/FutureChain.java
  • 起始行号:L11
  • 实现:TaskChainer, AutoCloseable
  • 职责:

    TODO

字段/常量

  • LOGGER

    • 类型: Logger
    • 修饰符: private static final
    • 源码定位: L12
    • 说明:

      TODO

  • head

    • 类型: CompletableFuture<?>
    • 修饰符: private
    • 源码定位: L13
    • 说明:

      TODO

  • executor

    • 类型: Executor
    • 修饰符: private final
    • 源码定位: L14
    • 说明:

      TODO

  • closed

    • 类型: boolean
    • 修饰符: private volatile
    • 源码定位: L15
    • 说明:

      TODO

内部类/嵌套类型

构造器

public FutureChain(Executor executor) @ L17

  • 构造器名:FutureChain
  • 源码定位:L17
  • 修饰符:public

参数:

  • executor: Executor

说明:

TODO

方法

下面的方法块按源码顺序生成。

public <T> void append(CompletableFuture<T> preparation, Consumer<T> chainedTask) @ L21

  • 方法名:append
  • 源码定位:L21
  • 返回类型: void
  • 修饰符:public

参数:

  • preparation: CompletableFuture
  • chainedTask: Consumer

说明:

TODO

public void close() @ L41

  • 方法名:close
  • 源码定位:L41
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

public class FutureChain implements TaskChainer, AutoCloseable {
    private static final Logger LOGGER = LogUtils.getLogger();
    private CompletableFuture<?> head = CompletableFuture.completedFuture(null);
    private final Executor executor;
    private volatile boolean closed;
 
    public FutureChain(Executor executor) {
        this.executor = executor;
    }
 
    @Override
    public <T> void append(CompletableFuture<T> preparation, Consumer<T> chainedTask) {
        this.head = this.head.<T, Object>thenCombine(preparation, (ignored, value) -> value).thenAcceptAsync(value -> {
            if (!this.closed) {
                chainedTask.accept((T)value);
            }
        }, this.executor).exceptionally(t -> {
            if (t instanceof CompletionException c) {
                t = c.getCause();
            }
 
            if (t instanceof CancellationException c) {
                throw c;
            } else {
                LOGGER.error("Chain link failed, continuing to next one", t);
                return null;
            }
        });
    }
 
    @Override
    public void close() {
        this.closed = true;
    }
}

引用的其他类