Package io.javago
Class DelayedCase
java.lang.Object
io.javago.DelayedCase
- All Implemented Interfaces:
Runnable
The
DelayedCase
class is used to create the timeout case found in Go's select
statement.
It represents a task that is executed after a specified delay.
It implements the Runnable
interface and allows a callback to be run after the delay.
DelayedCase
reserves a platform thread until its callback has completed execution so the delay and amount of
instances of this class currently running should be kept to a minimum.
Additionally, it sends an identifier to a specified output channel before and after executing the callback.-
Constructor Summary
ConstructorsConstructorDescriptionDelayedCase
(Duration delay, Runnable callback, OutputChannel<Integer> toSelector, int id, AtomicBoolean closed) Constructs aDelayedCase
with the specified delay, callback, output channel, identifier, and closed state. -
Method Summary
-
Constructor Details
-
DelayedCase
public DelayedCase(Duration delay, Runnable callback, OutputChannel<Integer> toSelector, int id, AtomicBoolean closed) Constructs aDelayedCase
with the specified delay, callback, output channel, identifier, and closed state.DelayedCase
reserves a platform thread until its callback has completed execution so the delay and amount of instances of this class currently running should be kept to a minimum.- Parameters:
delay
- the duration to wait before executing the callbackcallback
- the runnable to be executed after the delaytoSelector
- the output channel to send the identifierid
- the identifier to be sent to the output channelclosed
- the atomic boolean indicating the closed state
-
-
Method Details
-
run
public void run()Runs the delayed task. After the specified delay, it sends the identifier to the output channel, runs the callback, and sends the identifier again. If interrupted, it cancels the timer. Reserves a platform thread until its callback has completed execution so the delay and amount of instances of this class currently running should be kept to a minimum.
-