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 WsServer was created.

Example

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

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

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

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

Since

v5.0.0