swiftlys2/docs/api/ai/
API Reference Scheduler

ISchedulerService

Interface
Namespace: SwiftlyS2.Shared.Scheduler · Assembly: SwiftlyS2.CS2.dll
public interface ISchedulerService
View source

Methods

AddTimer(Func<ITimerContext, TimerStep>)

Add an advanced timer to the scheduler.

CancellationTokenSource AddTimer(Func<ITimerContext, TimerStep> task)
Parameters
Returns
A CancellationTokenSource that can be used to cancel the timer.

Delay(int, Action)

Add a delayed task to the scheduler.

CancellationTokenSource Delay(int delayTick, Action task)
Parameters
  • delayTickintThe delay of the timer in ticks.
  • taskActionThe task to execute.
Returns
A CancellationTokenSource that can be used to cancel the timer.

DelayAndRepeat(int, int, Action)

Add a delayed and repeated task to the scheduler.

CancellationTokenSource DelayAndRepeat(int delayTick, int periodTick, Action task)
Parameters
  • delayTickintThe delay of the timer in ticks.
  • periodTickintThe period of the timer in ticks.
  • taskActionThe task to execute.
Returns
A CancellationTokenSource that can be used to cancel the timer.

DelayAndRepeatBySeconds(float, float, Action)

Add a delayed and repeated task to the scheduler. The timing is based on game tick, which means it becomes inaccurate when intervals approachs 1 tick (approximately 15ms).

CancellationTokenSource DelayAndRepeatBySeconds(float delaySeconds, float periodSeconds, Action task)
Parameters
  • delaySecondsfloatThe delay of the timer in seconds.
  • periodSecondsfloatThe period of the timer in seconds.
  • taskActionThe task to execute.
Returns
A CancellationTokenSource that can be used to cancel the timer.

DelayBySeconds(float, Action)

Add a delayed task to the scheduler. The timing is based on game tick, which means it becomes inaccurate when intervals approachs 1 tick (approximately 15ms).

CancellationTokenSource DelayBySeconds(float delaySeconds, Action task)
Parameters
  • delaySecondsfloatThe delay of the timer in seconds.
  • taskActionThe task to execute.
Returns
A CancellationTokenSource that can be used to cancel the timer.

NextTick(Action)

Add a task to be executed on the next tick.

void NextTick(Action task)
Parameters
  • taskActionThe task to execute.

NextTick(Func<Task?>)

Never use this! you should never calls async callback in next tick, because async callback have chance to run in async context, which breaks the the synchronization safety this function gives.

[Obsolete("Please remove the async modifier on your callback for safety reason. See comments for more details.")]
void NextTick(Func<Task?> task)
Parameters
Exceptions

NextTick<T>(Func<Task<T?>>)

Never use this! you should never calls async callback in next tick, because async callback have chance to run in async context, which breaks the the synchronization safety this function gives.

[Obsolete("Please remove the async modifier on your callback for safety reason. See comments for more details.")]
void NextTick<T>(Func<Task<T?>> task)
Parameters
Exceptions

NextTickAsync(Action)

Add a task to be executed on the next tick asynchronously.

Task NextTickAsync(Action task)
Parameters
  • taskActionThe task to execute.
Returns

NextTickAsync(Func<Task?>)

Never use this! you should never calls async callback in next tick, because async callback have chance to run in async context, which breaks the the synchronization safety this function gives.

[Obsolete("Please remove the async modifier on your callback for safety reason. See comments for more details.")]
void NextTickAsync(Func<Task?> task)
Parameters
Exceptions

NextTickAsync<T>(Func<Task<T?>>)

Never use this! you should never calls async callback in next tick, because async callback have chance to run in async context, which breaks the the synchronization safety this function gives.

[Obsolete("Please remove the async modifier on your callback for safety reason. See comments for more details.")]
void NextTickAsync<T>(Func<Task<T?>> task)
Parameters
Exceptions

NextTickAsync<T>(Func<T>)

Add a task to be executed on the next tick asynchronously.

Task<T> NextTickAsync<T>(Func<T> task)
Parameters
  • taskFunc<T>The task to execute.
Returns
Task<T>

NextWorldUpdate(Action)

Add a task to be executed on the next world update.

void NextWorldUpdate(Action task)
Parameters
  • taskActionThe task to execute.

NextWorldUpdate(Func<Task?>)

Never use this! you should never calls async callback in next world update, because async callback have chance to run in async context, which breaks the the synchronization safety this function gives.

[Obsolete("Please remove the async modifier on your callback for safety reason. See comments for more details.")]
void NextWorldUpdate(Func<Task?> task)
Parameters
Exceptions

NextWorldUpdate<T>(Func<Task<T?>>)

Never use this! you should never calls async callback in next world update, because async callback have chance to run in async context, which breaks the the synchronization safety this function gives.

[Obsolete("Please remove the async modifier on your callback for safety reason. See comments for more details.")]
void NextWorldUpdate<T>(Func<Task<T?>> task)
Parameters
Exceptions

NextWorldUpdateAsync(Action)

Add a task to be executed on the next world update asynchronously.

Task NextWorldUpdateAsync(Action task)
Parameters
  • taskActionThe task to execute.
Returns

NextWorldUpdateAsync(Func<Task?>)

Never use this! you should never calls async callback in next world update, because async callback have chance to run in async context, which breaks the the synchronization safety this function gives.

[Obsolete("Please remove the async modifier on your callback for safety reason. See comments for more details.")]
void NextWorldUpdateAsync(Func<Task?> task)
Parameters
Exceptions

NextWorldUpdateAsync<T>(Func<Task<T?>>)

Never use this! you should never calls async callback in next world update, because async callback have chance to run in async context, which breaks the the synchronization safety this function gives.

[Obsolete("Please remove the async modifier on your callback for safety reason. See comments for more details.")]
Task<T> NextWorldUpdateAsync<T>(Func<Task<T?>> task)
Parameters
Returns
Task<T>
Exceptions

NextWorldUpdateAsync<T>(Func<T>)

Add a task to be executed on the next world update asynchronously.

Task<T> NextWorldUpdateAsync<T>(Func<T> task)
Parameters
  • taskFunc<T>The task to execute.
Returns
Task<T>

Repeat(int, Action)

Add a repeated task to the scheduler. This will be executed once immediately, and then every periodTick ticks.

CancellationTokenSource Repeat(int periodTick, Action task)
Parameters
  • periodTickintThe period of the timer in ticks.
  • taskActionThe task to execute.
Returns
A CancellationTokenSource that can be used to cancel the timer.

RepeatBySeconds(float, Action)

Add a repeated task to the scheduler. This will be executed once immediately, and then every periodSeconds seconds. The timing is based on game tick, which means it becomes inaccurate when intervals approachs 1 tick (approximately 15ms).

CancellationTokenSource RepeatBySeconds(float periodSeconds, Action task)
Parameters
  • periodSecondsfloatThe period of the timer in seconds.
  • taskActionThe task to execute.
Returns
A CancellationTokenSource that can be used to cancel the timer.

StopOnMapChange(CancellationTokenSource)

Stop a timer when the map changes.

void StopOnMapChange(CancellationTokenSource cts)
Parameters