Client Library Status

Retrieving the client state

The ZkBobClient object can be in various states throughout its lifecycle. To enable the application to understand what is happening in the library and respond appropriately to changes in its state, the set of states are introduced and organized into a state machine.

You can use your own callback to get the status changes in time. You can set it on client instantination or later with the object's field stateCallback of type ClientStateCallback. You can also remove it to stop status monitoring.

public stateCallback?: ClientStateCallback;

The following routines are introduced to monitor the client's state.

Getting the Client State

getState(): ClientState

Returns

ClientState enum member.

Example

const st = zkClient.getState();
if (st == ClientState.StateUpdating || st == ClientState.StateUpdatingContinuous) {
   console.log('Please wait while local state becomes up-to-dated');
}
// output: Please wait while local state becomes up-to-dated

Getting the Client Continuous State Progress

getProgress(): number | undefined;

Returns

number which represents progress for continuous states (from 0.0 to 1.0) or undefined for non-continuous states.

Example

const st = zkClient.getState();
const pr = zkClient.getProgress();
if (st == ClientState.StateUpdating) {
   const progressStr = (pr !== undefined ? `(${(pr * 100.0).toFixed(1)}%)` : '');
   console.log(`Please wait while local state becomes up-to-dated ${progressStr}`);
}
// output: Please wait while local state becomes up-to-dated (42.0%)

Last updated