Waiters
ZilaWS has a unique function called waiter
. Waiters (as their name suggests) can be awaited.
They resolve when a MessageHandler on the other side of the connection resolves or returns thus making it perfect for retrieving data.
However if the client or server does not respond in time, waiters will resolve as undefined.
- Regular
waiter
s wait for a response for the time specified by themaxWaiterTime
property.- On the server side this is a property of the server object.
- On the client side this is a property of the client object.
waiterTimeout
s wait for a response for the time specified by themaxWaitingTime
parameter in miliseconds.
Parameters
identifier
: The name of the MessageHandler on the other side of the connection.maxWaitingTime
: This paramater overrides the maximum waiting time for the correspondingwaiter
orbroadcastWaiter
. The value is in miliseconds....data
: A waiter (or a send) can be given any number of any data.
Waiter
- Server-side
- Client-side
socket.waiter<T>(identifier: string, ...data: any[]): Promise<T | undefined>
socket.waiterTimeout<T>(identifier: string, maxWaitingTime: number, ...data: any[]): Promise<T | undefined>
OR
server.waiter<T>(socket: ZilaClient, identifier: string, ...data: any[]): Promise<T | undefined>
server.waiterTimeout<T>(socket: ZilaClient, identifier: string, maxWaitingTime: number, ...data: any[]): Promise<T | undefined>
client.waiter<T>(identifier: string, ...data: any[]): Promise<T | undefined>
BroadcastWaiter
These functions only return values from those clients which respond in time.
server.broadcastWaiter<T>(identifier: string, ...data: any[]): Promise<Array<T>>
server.broadcastWaiterTimeout<T>(identifier: string, maxWaiterTime: number, ...data: any[]): Promise<Array<T>>