Class Concurrency

java.lang.Object
io.github.javactrl.ext.Concurrency

@Ctrl public class Concurrency extends Object
Various utilities for cooperative concurrency. So everything here is not (yet?) thread-safe. There are many usages of this in preemptive multithreading context, so probably this will be fixed at some point in the future.
  • Constructor Details

    • Concurrency

      public Concurrency()
  • Method Details

    • allOf

      public static <T> List<T> allOf(List<? extends CSupplier<? extends T>> components) throws CThrowable
      This function runs each item of the `components` list until all of them return, or one throws an exception. If every component returns, it returns a list of the returned values. If anything throws an exception, this will resume every suspended component with a throw of java.util.concurrent.CancellationException once, but it still waits while every component stops either by the returned value of an exception. They both are ignored. If the exception occurs before the next components are applied, they won't be applied.
      Type Parameters:
      T - type of the resulting value
      Parameters:
      components - suppliers for resulting item value
      Returns:
      list of resulting values
      Throws:
      CThrowable - if any of the components suspends the whole expression suspends
    • allOf

      @SafeVarargs public static <T> List<T> allOf(CSupplier<? extends T>... components) throws CThrowable
      A vararg short-cut to allOf(List)
      Type Parameters:
      T - type of the resulting value
      Parameters:
      components - suppliers for resulting item value
      Returns:
      list of resulting values
      Throws:
      CThrowable - if any of the components suspends the whole expression suspends
    • anyOf

      public static <T> T anyOf(List<? extends CSupplier<? extends T>> components) throws CThrowable
      This is mostly the same as allOf(List) except it stops execution after any of called components returns a resulting value or throws an exception. Like allOf(List) it resumes suspended components with CancelationException and awaits while everything exits either by value or any exception, ignoring them both. It returns the first returned value or the first thrown exception.
      Type Parameters:
      T - type of resulting value
      Parameters:
      components - suppliers for resulting item value
      Returns:
      the first returned value
      Throws:
      CThrowable - if any of the components suspends the whole expression suspends
    • anyOf

      @SafeVarargs public static <T> T anyOf(CSupplier<? extends T>... components) throws CThrowable
      A vararg short-cut to allOf(List)
      Type Parameters:
      T - type of resulting value
      Parameters:
      components - suppliers for resulting item value
      Returns:
      the first returned value
      Throws:
      CThrowable - if any of the components suspends the whole expression suspends