Package io.javago

Class DelayedCase

java.lang.Object
io.javago.DelayedCase
All Implemented Interfaces:
Runnable

public class DelayedCase extends Object implements 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 Details

    • DelayedCase

      public DelayedCase(Duration delay, Runnable callback, OutputChannel<Integer> toSelector, int id, AtomicBoolean closed)
      Constructs a DelayedCase 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 callback
      callback - the runnable to be executed after the delay
      toSelector - the output channel to send the identifier
      id - the identifier to be sent to the output channel
      closed - 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.
      Specified by:
      run in interface Runnable