Skip to content

Scheduler

Sam Bloomberg edited this page Apr 18, 2014 · 2 revisions

Dive's scheduler is a fairly simple system that executes tasks after a specified amount of time.

Scheduler Properties

The scheduler has the following properties. Some may affect the way you use it.

Timing is not guaranteed

The scheduler may execute tasks any time after they expire. They won't always execute exactly at the time you have specified for them. This is mostly because the scheduler will try to limit how much time it takes up in the game loop.

Tasks will always execute after they expire

They will never be executed before they expire.

At least one task will be run per update tick

The scheduler will always execute at least one task per update tick, such that task execution time cannot be completely starved by other processes, even if it means slowing down the game loop.

Recently expiring tasks will be executed after old expiring tasks

A task that was scheduled for 10 seconds ago will be executed before a task scheduled for 5 seconds ago.

Same-time task execution order is not guaranteed

Two tasks that have the same expiry time are not guaranteed to be executed in the same order every time.

TaskInfo Objects

To schedule a task, you must create a TaskInfo object.

Important Fields

ExecuteAfter

The time before expiring and executing this task.

Repeating

Whether or not this is a repeating task.

Task

The delegate to call when the task expires.

Completed

Whether or not this task has been completed. This can also be set to remove the task from the scheduler.

TimeLeft

The amount of time left until execution. This is set by the scheduler, and should not be changed.