Package de.esoco.coroutine.step
Class CodeExecution<I,O>
- java.lang.Object
-
- org.obrel.core.RelatedObject
-
- de.esoco.coroutine.CoroutineStep<I,O>
-
- de.esoco.coroutine.step.CodeExecution<I,O>
-
- All Implemented Interfaces:
de.esoco.lib.property.Fluent<CoroutineStep<I,O>>,org.obrel.core.FluentRelatable<CoroutineStep<I,O>>,org.obrel.core.Relatable
public class CodeExecution<I,O> extends CoroutineStep<I,O>
An coroutine step that executes a code function.
-
-
Constructor Summary
Constructors Constructor Description CodeExecution(java.util.function.BiFunction<I,Continuation<?>,O> code)Creates a new instance from a binary function that accepts the continuation of the execution and the input value.CodeExecution(java.util.function.Function<I,O> code)Creates a new instance from a simple function that processes the input into the output value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <I,O>
CodeExecution<I,O>apply(java.util.function.BiFunction<I,Continuation<?>,O> code)Applies aBiFunctionto the step input and the continuation of the current execution and return the processed output.static <I,O>
CodeExecution<I,O>apply(java.util.function.Function<I,O> code)Applies aFunctionto the step input and return the processed output.static <T> CodeExecution<T,T>consume(java.util.function.BiConsumer<T,Continuation<?>> code)Consumes the input value with aConsumerand returns the input value.static <T> CodeExecution<T,T>consume(java.util.function.Consumer<T> code)Consumes the input value with aConsumerand returns the input value.protected Oexecute(I input, Continuation<?> continuation)This method must be implemented by subclasses to provide the actual functionality of this step.static <I,O>
CodeExecution<I,O>getParameter(org.obrel.core.RelationType<O> rSource)Queries a parameter relation from theContinuationand returns it as the result of the execution.static <I,O>
CodeExecution<I,O>getScopeParameter(org.obrel.core.RelationType<O> rSource)Queries a parameter relation from theCoroutineScopeand returns it as the result of the execution.static <I,O>
CodeExecution<I,O>map(java.util.function.Function<I,O> mapper)A semantic alternative forapply(Function).static <T> CodeExecution<T,java.lang.Void>run(java.lang.Runnable code)Executes aRunnable, ignoring any input value and returning no result.static <T> CodeExecution<T,T>run(java.util.function.Consumer<Continuation<?>> code)Executes aRunnableand then returns the input value.static <T> CodeExecution<T,T>setParameter(org.obrel.core.RelationType<T> rTarget)Sets the input value into a parameter of theContinuationand then returns it.static <T> CodeExecution<T,T>setScopeParameter(org.obrel.core.RelationType<T> rTarget)Sets the input value into a parameter of theCoroutineScopeand then returns it.static <I,O>
CodeExecution<I,O>supply(java.util.function.Function<Continuation<?>,O> code)Provides a value from aSupplieras the result, ignoring any input value.static <I,O>
CodeExecution<I,O>supply(java.util.function.Supplier<O> code)Provides a value from aSupplieras the result, ignoring any input value.-
Methods inherited from class de.esoco.coroutine.CoroutineStep
runAsync, runBlocking, terminateCoroutine, toString
-
Methods inherited from class org.obrel.core.RelatedObject
deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
-
-
-
-
Constructor Detail
-
CodeExecution
public CodeExecution(java.util.function.BiFunction<I,Continuation<?>,O> code)
Creates a new instance from a binary function that accepts the continuation of the execution and the input value.- Parameters:
code- A binary function containing the code to be executed
-
-
Method Detail
-
apply
public static <I,O> CodeExecution<I,O> apply(java.util.function.Function<I,O> code)
Applies aFunctionto the step input and return the processed output.- Parameters:
code- The function to be executed- Returns:
- A new instance of this class
-
apply
public static <I,O> CodeExecution<I,O> apply(java.util.function.BiFunction<I,Continuation<?>,O> code)
Applies aBiFunctionto the step input and the continuation of the current execution and return the processed output.- Parameters:
code- The binary function to be executed- Returns:
- A new instance of this class
-
consume
public static <T> CodeExecution<T,T> consume(java.util.function.Consumer<T> code)
Consumes the input value with aConsumerand returns the input value.- Parameters:
code- The consumer to be executed- Returns:
- A new instance of this class
-
consume
public static <T> CodeExecution<T,T> consume(java.util.function.BiConsumer<T,Continuation<?>> code)
Consumes the input value with aConsumerand returns the input value.- Parameters:
code- The consumer to be executed- Returns:
- A new instance of this class
-
getParameter
public static <I,O> CodeExecution<I,O> getParameter(org.obrel.core.RelationType<O> rSource)
Queries a parameter relation from theContinuationand returns it as the result of the execution.- Parameters:
rSource- The relation type of the parameter- Returns:
- A new instance of this class
-
getScopeParameter
public static <I,O> CodeExecution<I,O> getScopeParameter(org.obrel.core.RelationType<O> rSource)
Queries a parameter relation from theCoroutineScopeand returns it as the result of the execution.- Parameters:
rSource- The relation type of the parameter- Returns:
- A new instance of this class
-
map
public static <I,O> CodeExecution<I,O> map(java.util.function.Function<I,O> mapper)
A semantic alternative forapply(Function).- Parameters:
mapper- The mapping function- Returns:
- A new instance of this class
-
run
public static <T> CodeExecution<T,java.lang.Void> run(java.lang.Runnable code)
Executes aRunnable, ignoring any input value and returning no result.- Parameters:
code- The runnable to be executed- Returns:
- A new instance of this class
-
run
public static <T> CodeExecution<T,T> run(java.util.function.Consumer<Continuation<?>> code)
Executes aRunnableand then returns the input value.- Parameters:
code- The runnable to be executed- Returns:
- A new instance of this class
-
setParameter
public static <T> CodeExecution<T,T> setParameter(org.obrel.core.RelationType<T> rTarget)
Sets the input value into a parameter of theContinuationand then returns it.- Parameters:
rTarget- The type of the relation to set the parameter in- Returns:
- A new instance of this class
-
setScopeParameter
public static <T> CodeExecution<T,T> setScopeParameter(org.obrel.core.RelationType<T> rTarget)
Sets the input value into a parameter of theCoroutineScopeand then returns it.- Parameters:
rTarget- The type of the relation to set the parameter in- Returns:
- A new instance of this class
-
supply
public static <I,O> CodeExecution<I,O> supply(java.util.function.Supplier<O> code)
Provides a value from aSupplieras the result, ignoring any input value.- Parameters:
code- The supplier to be executed- Returns:
- A new instance of this class
-
supply
public static <I,O> CodeExecution<I,O> supply(java.util.function.Function<Continuation<?>,O> code)
Provides a value from aSupplieras the result, ignoring any input value.- Parameters:
code- The supplier to be executed- Returns:
- A new instance of this class
-
execute
protected O execute(I input, Continuation<?> continuation)
This method must be implemented by subclasses to provide the actual functionality of this step.- Specified by:
executein classCoroutineStep<I,O>- Parameters:
input- The input valuecontinuation- The continuation of the execution- Returns:
- The result of the execution
-
-