Skip to content

Instantly share code, notes, and snippets.

Avatar

Viper Bailey jinxidoru

View GitHub Profile
@jinxidoru
jinxidoru / closeable_http_server.ts
Last active Feb 11, 2020
Closeable http server
View closeable_http_server.ts
import * as http from 'http'
import * as _ from 'lodash'
//! In the standard implementation of http server, calling close is not guaranteed to close the
//! server. Any idle connections being kept alive by clients will stay open until their timeout
//! is reached. This is problematic for gracefully shutting down a process with an http server.
//! This function will create an http server that tracks the open connections. On close, idle
//! connections are closed and any newly idled connection is immediately closed as well. When there
//! are no more connections on the server, the 'empty' event is raised.