MainThreadJobHandler
A class in Root.Township, the global namespace.
Singleton that runs scheduled work on the main thread a bit each frame, within a time budget. Other threads await the returned Entry; world generation uses it for raycasts.
- Listed in Global namespace: M to O
- Inherits or implements
SingletonBehaviour<MainThreadJobHandler> - Derived types
MainThreadJobHandler - Nested types
Entry,InternalEntry
Constructors
| Member | What it is |
|---|---|
MainThreadJobHandler() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
7 private and internal fields
| Member | What it is |
|---|---|
private MainThreadJobHandler.InternalEntry current | The job being run, kept across frames when it runs out of time. |
private ConcurrentQueue<MainThreadJobHandler.InternalEntry> entries | Thread-safe queue of waiting jobs. |
private float millisecondAllowance | Milliseconds of jobs allowed per frame (default 3). |
private uint nextIndex | Counter for job indexes. |
private ConcurrentBag<MainThreadJobHandler.InternalEntry> pool | Pool of reusable entries. Nothing returns entries to it, so it stays empty. |
private int remainingCount | Read-only inspector count that nothing updates. |
private Stopwatch timer | Stopwatch for the per-frame budget. |
Methods
| Member | What it is |
|---|---|
MainThreadJobHandler.Entry Schedule(Action getTask, CancellationToken cancellationToken = null) | Queues an action or a step-by-step IEnumerable job and returns an awaitable entry that gives false if cancelled. |
MainThreadJobHandler.Entry Schedule(Func<IEnumerable> getTask, CancellationToken cancellationToken = null) | Queues an action or a step-by-step IEnumerable job and returns an awaitable entry that gives false if cancelled. |