Skip to main content

Thread

class Thread 

A class representing an individual thread.

Thread is a wrapper for a generator that can be executed concurrently.

Aside from the main thread, all threads need to have a parent. If a parent finishes execution, all of its child threads are terminated.

Constructors​

constructor​

public new Threadrunner: ThreadGeneratortask?: Thread: Thread

Parameters

Properties​

children​

public children: Thread[] = []

parent​

public parent: nullThread = null

runner​

readonly public runner: ThreadGeneratortask?: Thread

The generator wrapped by this thread.


time​

readonly public time: SimpleSignalnumbervoid = ...

The current time of this thread.

Used by waitFor and other time-based functions to properly support durations shorter than one frame.


value​

public value: unknown

The next value to be passed to the wrapped generator.

Accessors​

canceled​

public get canceled(): boolean

Check if this thread or any of its ancestors has been canceled.


fixed​

public get fixed(): number

The fixed time of this thread.

Fixed time is a multiple of the frame duration. It can be used to account for the difference between this thread's time and the time of the current animation frame.


onDeferred​

public get onDeferred(): SubscribablevoidEventHandlervoid

paused​

public get paused(): boolean

root​

public get root(): Thread

Methods​

add​

public addchild: Thread: void

Parameters


cancel​

public cancel(): void

drain​

public draincallback: task: ThreadGenerator => void: void

Parameters


next​

public next(): IteratorYieldResultvoidPromiseanyThreadGeneratorPromisableanyIteratorReturnResultvoiddone: boolean = falsevalue: null = null

Progress the wrapped generator once.


pause​

public pausevalue: boolean: void

Parameters


runDeferred​

public runDeferred(): void

spawn​

Parameters


update​

public updatedt: number: void

Prepare the thread for the next update cycle.

Parameters

  • dt: number

    The delta time of the next cycle.