Class Scheduler
- Namespace
- MarymoorStudios.Core.Promises
- Assembly
- MarymoorStudios.Core.Promises.dll
A scheduler of turns.
public sealed class Scheduler : IDisposable
- Inheritance
-
Scheduler
- Implements
- Inherited Members
Constructors
Scheduler()
public Scheduler()
Properties
Current
The current scheduler.
public static Scheduler Current { get; set; }
Property Value
Remarks
Only one scheduler can be active on a thread at one time.
Id
The diagnostic id of the current scheduler.
public static DiagnosticId Id { get; }
Property Value
IsAttached
True if a scheduler is attached to the current thread.
public static bool IsAttached { get; }
Property Value
Methods
AddExternal(Action)
Adds an external (thread-safe) turn to the external turn queue.
public void AddExternal(Action turn)
Parameters
turn
Action
Remarks
The caller is responsible for ensuring that turn
does not close over any
non-thread safe state.
AddExternal(Action<object?, object?, object?>, object?, object?, object?)
Adds an external (thread-safe) turn to the external turn queue.
public void AddExternal(Action<object?, object?, object?> turn, object? state1, object? state2, object? state3)
Parameters
turn
Action<object, object, object>state1
object1st state to be passed to the action.
state2
object2nd state to be passed to the action.
state3
object3rd state to be passed to the action.
Remarks
The caller is responsible for ensuring that turn
does not close over any
non-thread safe state.
AddExternal(Action<object?, object?>, object?, object?)
Adds an external (thread-safe) turn to the external turn queue.
public void AddExternal(Action<object?, object?> turn, object? state1, object? state2)
Parameters
turn
Action<object, object>state1
object1st state to be passed to the action.
state2
object2nd state to be passed to the action.
Remarks
The caller is responsible for ensuring that turn
does not close over any
non-thread safe state.
AddExternal(Action<object?>, object?)
Adds an external (thread-safe) turn to the external turn queue.
public void AddExternal(Action<object?> turn, object? state)
Parameters
Remarks
The caller is responsible for ensuring that turn
does not close over any
non-thread safe state.
Delay(TimeSpan)
Creates a promise that will resolve after a time delay.
public static Promise Delay(TimeSpan delay)
Parameters
delay
TimeSpanThe time span to wait.
Returns
Detach()
Detaches a scheduler from the current thread.
public void Detach()
Remarks
Attempts to detach a scheduler from the current thread. If the given scheduler is NOT the current scheduler on the thread (perhaps because it has already been detached or disposed) then this method does nothing.
Dispose()
public void Dispose()
Register(Runner)
Registers a Runner with this scheduler.
public static void Register(Runner runner)
Parameters
runner
RunnerThe runner to register.
Remarks
The scheduler takes "ownership" of the runner and will dispose its resources.
Run(Turn)
Runs an abstract turn on the current scheduler.
public static void Run(Turn turn)
Parameters
turn
TurnThe turn to run.
Run(Func<Promise>)
Runs an abstract eventual function on the current scheduler.
public static Promise Run(Func<Promise> func)
Parameters
Returns
Run(CancellationToken)
Converts a cancellation token into a Promise on the current scheduler.
public static Promise Run(CancellationToken cancel)
Parameters
cancel
CancellationTokenThe cancellation token to convert.
Returns
RunUntilCancelled(CancellationToken, bool)
Runs all turns (internal and external) until cancellation is signaled.
public bool RunUntilCancelled(CancellationToken cancel, bool canBlock = true)
Parameters
cancel
CancellationTokenThe cancellation token to cancel operation.
canBlock
boolTrue if the loop should block on IO (or exit).
Returns
- bool
True if there is more local work to do, or false if blocked on IO or cancelled.
Unregister(Runner)
Unregisters a Runner from this scheduler.
public static void Unregister(Runner runner)
Parameters
runner
RunnerThe runner to unregister.