TinyBase logoTinyBase

destroy

The destroy method provides a way to clean up the server at the end of its use.

destroy(): void

This closes the underlying WebSocketServer that was provided when the WsServerSimple was created.

Example

This example creates a WsServerSimple and then destroys it again, closing the underlying WebSocketServer.

import {WebSocketServer} from 'ws';
import {createWsServerSimple} from 'tinybase/synchronizers/synchronizer-ws-server-simple';

const webSocketServer = new WebSocketServer({port: 8053});
webSocketServer.on('close', () => {
  console.log('WebSocketServer closed');
});
const server = createWsServerSimple(webSocketServer);

server.destroy();
// ...
// -> 'WebSocketServer closed'

Since

v5.4.0