Package ghidra.async

Class AsyncFence

java.lang.Object
ghidra.async.AsyncFence

public class AsyncFence extends Object
A fence that completes when all participating futures complete

This provides an alternative shorthand for Java's CompletableFuture.thenAcceptBoth(CompletionStage, BiConsumer) or CompletableFuture.allOf(CompletableFuture...).

Example:


 public CompletableFuture<Void> processAll(List<Integer> list) {
 	AsyncFence fence = new AsyncFence();
 	for (int entry : list) {
 		fence.include(process(entry));
 	}
 	return fence.ready();
 }
 
  • Constructor Details

    • AsyncFence

      public AsyncFence()
  • Method Details

    • include

      public AsyncFence include(CompletableFuture<?> future)
      Include a participant with this fence The result of the participating future is ignored implicitly. If the result is needed, it must be consumed out of band, e.g., by using CompletableFuture.thenAccept(Consumer):
       fence.include(process(entry).thenAccept(result::addTo));
       
      Calling this method after ready() will yield undefined results.
      Parameters:
      future - the participant to add
      Returns:
      this fence
    • ready

      public CompletableFuture<Void> ready()
      Obtain a future that completes when all participating futures have completed Calling this method more than once will yield undefined results.
      Returns:
      the "all of" future
    • getPending

      public Set<CompletableFuture<?>> getPending()
      Diagnostic: Get the participants which have not yet completed
      Returns:
      the pending participants