public class Delay<T> extends CoroutineStep<T,T>
Coroutine
step that performes delayed executions.Constructor and Description |
---|
Delay(org.obrel.core.RelationType<de.esoco.lib.datatype.Pair<java.lang.Long,java.util.concurrent.TimeUnit>> rDurationType,
long nDuration,
java.util.concurrent.TimeUnit eUnit)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
T |
execute(T rInput,
Continuation<?> rContinuation)
This method must be implemented by subclasses to provide the actual
functionality of this step.
|
void |
runAsync(java.util.concurrent.CompletableFuture<T> fPreviousExecution,
CoroutineStep<T,?> rNextStep,
Continuation<?> rContinuation)
Runs this execution step asynchronously as a continuation of a previous
code execution in a
CompletableFuture and proceeds to the next
step afterwards. |
static <T> Delay<T> |
sleep(int nMilliseconds)
Suspends the coroutine execution for a certain duration in milliseconds.
|
static <T> Delay<T> |
sleep(int nDuration,
java.util.concurrent.TimeUnit eUnit)
Suspends the coroutine execution for a certain duration.
|
static <T> Delay<T> |
sleep(org.obrel.core.RelationType<de.esoco.lib.datatype.Pair<java.lang.Long,java.util.concurrent.TimeUnit>> rDurationType)
Suspends the coroutine execution for a duration stored in a certain state
relation.
|
fail, runBlocking, terminateCoroutine, toString
deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public Delay(org.obrel.core.RelationType<de.esoco.lib.datatype.Pair<java.lang.Long,java.util.concurrent.TimeUnit>> rDurationType, long nDuration, java.util.concurrent.TimeUnit eUnit)
rDurationType
- The relation type to store the delay duration innDuration
- The duration to pauseeUnit
- The time unit of the durationpublic static <T> Delay<T> sleep(int nMilliseconds)
nMilliseconds
- The milliseconds to sleepsleep(int, TimeUnit)
public static <T> Delay<T> sleep(org.obrel.core.RelationType<de.esoco.lib.datatype.Pair<java.lang.Long,java.util.concurrent.TimeUnit>> rDurationType)
Continuation.getState(RelationType, Object)
.rDurationType
- The relation type of the sleep durationpublic static <T> Delay<T> sleep(int nDuration, java.util.concurrent.TimeUnit eUnit)
StandardTypes.DURATION
.nDuration
- The duration to sleepeUnit
- The time unit of the durationpublic T execute(T rInput, Continuation<?> rContinuation)
execute
in class CoroutineStep<T,T>
rInput
- The input valuerContinuation
- The continuation of the executionpublic void runAsync(java.util.concurrent.CompletableFuture<T> fPreviousExecution, CoroutineStep<T,?> rNextStep, Continuation<?> rContinuation)
CompletableFuture
and proceeds to the next
step afterwards.
Subclasses that need to suspend the invocation of the next step until
some condition is met (e.g. sending or receiving data has finished) need
to override this method and create a Suspension
by invoking
Continuation.suspend(CoroutineStep, CoroutineStep)
on the next
step. If the condition that caused the suspension resolves the coroutine
execution can be resumed by calling Suspension.resume(Object)
.
Subclasses that override this method also need to handle errors by
terminating any further execution (i.e. not resuming a suspension if such
exists) and forwarding the causing exception to Continuation.fail(Throwable)
.
runAsync
in class CoroutineStep<T,T>
fPreviousExecution
- The future of the previous code executionrNextStep
- The next step to execute or NULL for nonerContinuation
- The continuation of the execution