Package io.github.javactrl.ext
Class Concurrency
java.lang.Object
io.github.javactrl.ext.Concurrency
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>A vararg short-cut toallOf(List)static <T> List<T>This function runs each item of the `components` list until all of them return, or one throws an exception.static <T> TA vararg short-cut toallOf(List)static <T> TThis is mostly the same asallOf(List)except it stops execution after any of called components returns a resulting value or throws an exception.
-
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 ofjava.util.concurrent.CancellationExceptiononce, 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 toallOf(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
This is mostly the same asallOf(List)except it stops execution after any of called components returns a resulting value or throws an exception. LikeallOf(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
A vararg short-cut toallOf(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
-