Skip to content

Threads

Where plugin code runs: draws on the render thread, ticks on the game thread. Unless a plugin drives ticks, they’re the same thread and each tick runs just before its draw.

cancel(): void

Fine to call twice, or from inside one.

Says a plugin’s done winding down, from onStopping.

done(): void

Any thread. Fine to call twice.

Handed to a thread of its own, see startThread.

stopping(): boolean
sleep(ms: number): boolean

Asked to stop, by Running.stop or as the plugin unloads. Return soon after. Its thread.

Up to ms, waking early when asked to stop. False once asked. Its thread.

stop(): void

Asks it to stop and waits for it to return. Not from the thread itself. Fine to call twice.

Get it with Api.threads().

onDraw(draw: Wraith.Threads.Draw): Wraith.Threads.Subscription
onTick(tick: Wraith.Threads.Tick): Wraith.Threads.Subscription
claimTicks(changed: Wraith.Lease.Changed | null): Wraith.Lease
runTick(): void
onStopping(stopping: Wraith.Threads.Stopping): Wraith.Threads.Subscription
onGameThread(): boolean
post(task: Wraith.Threads.Task): void
now(): number
nextDraw(): Promise<void>
nextTick(): Promise<void>
toRender(): Promise<void>
toGame(): Promise<void>
toWorker(): Promise<void>
delay(ms: number): Promise<void>
run(name: string, job: Wraith.Threads.Job): void
startThread(name: string, main: Wraith.Threads.ThreadMain): Wraith.Threads.Running

Once a frame on the render thread, for UI. Gone with the plugin.

Fails with ThreadsError. Uses Threads.Draw, Threads.Subscription.

Once a tick on the game thread, for game logic. Gone with the plugin.

Fails with ThreadsError. Uses Threads.Tick, Threads.Subscription.

A lease on ticks, see Lease. While held, ticks run on its runTick and wait for the first, so claim in start. Unheld, they’re back on the render thread.

Fails with ThreadsError. Uses Lease.Changed, Lease.

Once a game frame on the game’s thread, from the ticks holder. Runs every onTick. A no-op otherwise. Not tick, which C# would make the same name as Tick.

Before unload, to undo game changes from the right thread. Call wind_down.done when finished; Wraith waits up to a second. Not when the game’s closing. Gone with the plugin.

Fails with ThreadsError. Uses Threads.Stopping, Threads.Subscription.

Whether this is the tick thread. False everywhere till the first tick.

Any thread. Posted from inside a task, it waits a draw.

Fails with ThreadsError. Uses Threads.Task.

Milliseconds on a steady clock, with fractions. Any thread.

At the start of the next draw, before its tick, on the render thread. Any thread.

Async. Fails with ThreadsError.

At the next tick, on the game thread.

Async. Fails with ThreadsError.

On the render thread, right away if already there, else at the next draw.

Async. Fails with ThreadsError.

On the game thread, right away if already there, else at its next tick. Never block there.

Async. Fails with ThreadsError.

On a worker, for slow or blocking work. Right away if already on one.

Async. Fails with ThreadsError.

After ms milliseconds, back on the calling thread (its next draw or tick for those threads).

Async. Fails with ThreadsError.

Once on a worker. Fine to block, like on a download.

Fails with ThreadsError. Uses Threads.Job.

A thread of its own, for a loop that runs while the plugin does. Stopped and waited for as it unloads, after onStopping.

Fails with ThreadsError. Uses Threads.ThreadMain, Threads.Running.

What can go wrong, besides Cancelled, Unsupported and Gone.

Code Error
1 NoFrames
2 Failed
3 NotForScripts Scripts run one thread at a time. await async calls instead, or use a native plugin

Once a frame on the render thread, inside an ImGui frame (a headless one if the overlay can’t draw).

Wraith.Threads.Draw

Once, on the render thread at the start of the next draw, before its tick.

Wraith.Threads.Task

Once a tick on the game thread. No drawing here.

Wraith.Threads.Tick

As the plugin’s about to stop, with everything still working.

Wraith.Threads.Stopping

Once, on a worker, for run.

Wraith.Threads.Job

A thread’s loop. Returns once thread.stopping() says so.

Wraith.Threads.ThreadMain

Made with ♥ by Asgard