Skip to main content

Class: Wait

A utility class for generating Promises that wait for certain conditions before they are fulfilled.

Constructors

constructor

new Wait(): Wait

Returns

Wait

Methods

awaitCondition

awaitCondition(predicate, interval?, timeout?): Promise<void>

Waits for a condition to be satisfied.

Parameters

NameTypeDefault valueDescription
predicate() => booleanundefinedA function which evaluates whether the condition is satisfied.
intervalnumber0The interval, in milliseconds, at which to evaluate the condition. A zero or negative value causes the condition to be evaluated every frame. Defaults to 0.
timeoutnumber0The amount of time, in milliseconds, before the returned Promise is rejected if the condition is not satisfied. A zero or negative value causes the Promise to never be rejected and the condition to be continually evaluated until it is satisfied. Defaults to 0.

Returns

Promise<void>

a Promise which is fulfilled when the condition is satisfied.

Defined in

src/sdk/utils/time/Wait.ts:59


awaitConsumer

awaitConsumer<T>(consumer, predicate?, initialCheck?, timeout?): Promise<T>

Waits for an event from a Consumer, with an optional condition to end the wait based on the value of the consumed event.

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
consumerConsumer<T>undefinedThe event consumer to wait for.
predicate?(value: T) => booleanundefinedA function which evaluates whether the value of the consumed event satisfies the condition for the wait to end. If not defined, any value is considered satisfactory.
initialCheckbooleanfalseWhether to immediately receive an event from the event consumer at the start of the wait. Defaults to false.
timeoutnumber0The amount of time, in milliseconds, before the returned Promise is rejected if the condition is not satisfied. A zero or negative value causes the Promise to never be rejected. Defaults to 0.

Returns

Promise<T>

A Promise which is fulfilled with the value of the consumed event when an event is received with a value that satisfies the condition for the wait to end.

Defined in

src/sdk/utils/time/Wait.ts:132


awaitDelay

awaitDelay(delay): Promise<void>

Waits for a set amount of time.

Parameters

NameTypeDescription
delaynumberThe amount of time to wait in milliseconds.

Returns

Promise<void>

a Promise which is fulfilled after the delay.

Defined in

src/sdk/utils/time/Wait.ts:13


awaitFrames

awaitFrames(count, glassCockpitRefresh?): Promise<void>

Waits for a certain number of frames to elapse.

Parameters

NameTypeDefault valueDescription
countnumberundefinedThe number of frames to wait.
glassCockpitRefreshbooleanfalseWhether to wait for glass cockpit refresh frames instead of CoherentGT frames. Defaults to false.

Returns

Promise<void>

Defined in

src/sdk/utils/time/Wait.ts:23


awaitSubEvent

awaitSubEvent<SenderType, DataType>(event, predicate?, timeout?): Promise<DataType>

Waits for an event from a ReadonlySubEvent, with an optional condition to end the wait based on the sender and data of the event.

Type parameters

Name
SenderType
DataType

Parameters

NameTypeDefault valueDescription
eventReadonlySubEvent<SenderType, DataType>undefinedThe event to wait for.
predicate?(data: DataType, sender: SenderType) => booleanundefinedA function which evaluates whether the sender and data of the event satisfy the condition for the wait to end. If not defined, any sender/data is considered satisfactory.
timeoutnumber0The amount of time, in milliseconds, before the returned Promise is rejected if the condition is not satisfied. A zero or negative value causes the Promise to never be rejected. Defaults to 0.

Returns

Promise<DataType>

A Promise which is fulfilled with the data of the event when an event is received with a sender and data that satisfy the condition for the wait to end.

Defined in

src/sdk/utils/time/Wait.ts:164


awaitSubscribable

awaitSubscribable<T>(subscribable, predicate?, initialCheck?, timeout?): Promise<T>

Waits for a notification from a Subscribable, with an optional condition to end the wait based on the value of the subscribable.

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
subscribableSubscribable<T>undefinedThe subscribable to wait for.
predicate?(value: T) => booleanundefinedA function which evaluates whether the value of the subscribable satisfies the condition for the wait to end. If not defined, any value is considered satisfactory.
initialCheckbooleanfalseWhether to immediately receive a notification from the subscribable at the start of the wait. Defaults to false.
timeoutnumber0The amount of time, in milliseconds, before the returned Promise is rejected if the condition is not satisfied. A zero or negative value causes the Promise to never be rejected. Defaults to 0.

Returns

Promise<T>

A Promise which is fulfilled with the value of the subscribable when a notification is received with a value that satisfies the condition for the wait to end.

Defined in

src/sdk/utils/time/Wait.ts:98