waitForState

In other words, it waits until a game state is set. This is useful for waiting for the host to set the winner, for example.

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

Signature

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

Parameters

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

Returns

Promise<any>

Usage

const winner = await waitForState('winner');
console.log(`Winner: ${winner}`);