API ReferenceJavaScript APIwaitForPlayerState()

waitForPlayerState

In other words, it waits until a player state is set. This is useful for waiting for a player to play their turn, for example.

Optionally, you can pass a callback that will be called when the state is set.

Signature

function waitForPlayerState(player: PlayerState, stateKey: string, onStateSetCallback?: (value: any) => void): Promise<any>

Parameters

NameTypeDescription
playerPlayerStateThe PlayerState object to observe.
stateKeystringThe key to wait for.
onStateSetCallback?(value: any) => voidOptional callback invoked when the state is set.

Returns

Promise<any>

Usage

await waitForPlayerState(player, 'playedTurn');