Skip to content

08. Routines

David Shnayder edited this page Jan 4, 2024 · 1 revision

Routines

Routines are special objects that contain a collection of actions and executes them once a specified interval has passed, until it is stopped. This was inspired by Coroutines from the Unity game engine.

Routine

The default Routine is the simplest version, it has a collection of Actions and once every timer interval has passed they get executed sequentially.

AsyncRoutine

AsyncRoutine is more complicated but more precise and more flexible, by providing a CancellationTokenSource, the AsyncRoutine can create tasks that will all run only while the source isn't cancelled.

In addition it can be initialized with a RoutineOptions that configures 2 important aspects:

  1. ThrowOnCancellation will cause an exception to be thrown when the source is cancelled, if left out, the routine will gracefully cancel all the tasks and exit quietly.
  2. ExecuteInParallel will configure the routine to execute the tasks concurrently and not sequentially which is the default.
Clone this wiki locally