Sending data
Waiter
ZilaWS has a unique function called waiter. Waiters (as their name states) can be awaited.
They only resolve when the MessageHandler
on the client side resolves or returns thus making it perfect to retrieve data from a client.
However if the client does not respond in time, waiters will resolve as undefined.
Syntax
waiter<T>(eventHandlerName: string, ...data: any[]): Promise<T | undefined>
- Client Side
- Server Side
const response: string | undefined = await client.waiter("Example name", "myData", true);
server.setMessageHandler("Example name", (data1: string, data2: boolean) => {
//Your code here...
return "This is message from the client side";
});
Send
You can send data / trigger a MessageHandler
by calling the send
function.
You can send any number of variables with any types.
Syntax
send(eventHandlerName: string, ...data: any[])
- Client Side
- Server Side
client.send("Example name", "myData", true);
server.setMessageHandler("Example name", (data1: string, data2: boolean) => {
//Your code here...
});