destroy
The destroy
method provides a way to clean up the server at the end of its use.
destroy(): Promise<void>
returns | Promise<void> |
---|
This closes the underlying WebSocketServer that was provided when the WsServer
was created. This method is asynchronous.
Example
This example creates a WsServer
and then destroys it again, closing the underlying WebSocketServer.
import {createWsServer} from 'tinybase/synchronizers/synchronizer-ws-server';
import {WebSocketServer} from 'ws';
const webSocketServer = new WebSocketServer({port: 8047});
webSocketServer.on('close', () => {
console.log('WebSocketServer closed');
});
const server = createWsServer(webSocketServer);
await server.destroy();
// ...
// -> 'WebSocketServer closed'
Since
v5.0.0