Table of Contents

Method RegisterAsyncTimer

Namespace
KZDev.PrimeTime
Assembly
KZDev.PrimeTime.dll

RegisterAsyncTimer(IPrimeClock, Duration, Func<CancellationToken, ValueTask>, CancellationToken, bool, IntervalTimerOptions?)

Registers a one-shot or repeating interval timer with an asynchronous callback.

public static IClockIntervalTimer RegisterAsyncTimer(this IPrimeClock clock, Duration callbackTime, Func<CancellationToken, ValueTask> callback, CancellationToken cancellationToken, bool repeat = false, IntervalTimerOptions? timerOptions = null)

Parameters

clock IPrimeClock

The clock on which to register the timer.

callbackTime Duration

Duration until the first callback.

callback Func<CancellationToken, ValueTask>

The async callback (returns ValueTask).

cancellationToken CancellationToken

Token that participates in cancelling the timer registration and is passed to the callback; use None when no external cancellation is required.

repeat bool

If true, repeat using callbackTime as the interval.

timerOptions IntervalTimerOptions

Optional timer options.

Returns

IClockIntervalTimer

An IClockIntervalTimer to monitor or change the timer.

RegisterAsyncTimer(IPrimeClock, Duration, Func<ClockTimerCallbackContext, CancellationToken, ValueTask>, CancellationToken, object?, bool, IntervalTimerOptions?)

Registers a one-shot or repeating interval timer with an asynchronous callback that receives context and cancellation token.

public static IClockIntervalTimer RegisterAsyncTimer(this IPrimeClock clock, Duration callbackTime, Func<ClockTimerCallbackContext, CancellationToken, ValueTask> callback, CancellationToken cancellationToken, object? state = null, bool repeat = false, IntervalTimerOptions? timerOptions = null)

Parameters

clock IPrimeClock

The clock on which to register the timer.

callbackTime Duration

Duration until the first callback.

callback Func<ClockTimerCallbackContext, CancellationToken, ValueTask>

The async callback; receives timer context and a cancellation token.

cancellationToken CancellationToken

Token that participates in cancelling the timer registration and is passed to the callback; use None when no external cancellation is required.

state object

Optional state passed to the callback via ClockTimerCallbackContext.

repeat bool

If true, repeat using callbackTime as the interval.

timerOptions IntervalTimerOptions

Optional timer options.

Returns

IClockIntervalTimer

An IClockIntervalTimer to monitor or change the timer.

RegisterAsyncTimer(IPrimeClock, Duration, Duration, Func<CancellationToken, ValueTask>, CancellationToken, IntervalTimerOptions?)

Registers an interval timer with an initial delay and a separate repeat interval (async callback).

public static IClockIntervalTimer RegisterAsyncTimer(this IPrimeClock clock, Duration callbackTime, Duration repeatInterval, Func<CancellationToken, ValueTask> callback, CancellationToken cancellationToken, IntervalTimerOptions? timerOptions = null)

Parameters

clock IPrimeClock

The clock on which to register the timer.

callbackTime Duration

Duration until the first callback.

repeatInterval Duration

Interval for subsequent callbacks; use a non-positive duration for one-shot.

callback Func<CancellationToken, ValueTask>

The async callback (returns ValueTask).

cancellationToken CancellationToken

Token that participates in cancelling the timer registration and is passed to the callback; use None when no external cancellation is required.

timerOptions IntervalTimerOptions

Optional timer options.

Returns

IClockIntervalTimer

An IClockIntervalTimer to monitor or change the timer.