destroyable-server
Version:
A tiny Node.js module to make any server force-closeable
22 lines (21 loc) • 820 B
TypeScript
/// <reference types="node" />
import * as net from 'net';
export type DestroyableServer<S extends net.Server = net.Server> = S & {
/**
* Forcibly shut down the server - destroying all active connections, and then
* calling `.close()``
*/
destroy(): Promise<void>;
};
/**
* Makes a server 'destroyable': tracks all active server connections, and adds a
* `.destroy()` method to the server, which destroys all active server connections
* and then shuts the server down cleanly.
*
* The server is mutated (adding the new method) and also returned from this method
* for convenience.
*
* `.destroy()` returns a promise, which you can wait on to ensure the server has
* been fully destroyed.
*/
export declare function makeDestroyable<S extends net.Server>(server: S): DestroyableServer<S>;