Created
March 2, 2021 11:01
-
-
Save fox1t/7be1b459c71d87a10c21ffa73584097a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare namespace closeWithGrace { | |
interface Options { | |
/** | |
* The numbers of milliseconds before abruptly close the process | |
* @default 10000 | |
*/ | |
delay: number; | |
} | |
type Signals = "SIGTERM" | "SIGINT"; | |
interface CloseWithGraceCallback { | |
( | |
options: { err?: Error; signal?: Signals; manual?: boolean }, | |
cb: (error?: Error) => void | |
): void; | |
} | |
interface CloseWithGraceAsyncCallback { | |
(options: { | |
err?: Error; | |
signal?: Signals; | |
manual?: boolean; | |
}): Promise<void>; | |
} | |
} | |
/** | |
@example | |
import * as closeWithGrace from 'close-with-grace' | |
// delay is the number of milliseconds for the graceful close to | |
// finish. | |
closeWithGrace({ delay: 500 }, async function ({ signal, err, manual }) { | |
if (err) { | |
console.error(err) | |
} | |
await closeYourServer() | |
}) | |
*/ | |
declare interface CloseWithGraceReturn { | |
/** | |
* Close the process, the manual argument will be set to true. | |
*/ | |
close: () => void; | |
/** | |
* Remove all global listeners | |
*/ | |
uninstall: () => void; | |
} | |
declare function closeWithGrace( | |
opts: | |
| closeWithGrace.CloseWithGraceAsyncCallback | |
| closeWithGrace.CloseWithGraceCallback | |
| closeWithGrace.Options | |
): CloseWithGraceReturn; | |
declare function closeWithGrace( | |
opts: closeWithGrace.Options, | |
fn?: | |
| closeWithGrace.CloseWithGraceCallback | |
| closeWithGrace.CloseWithGraceAsyncCallback | |
): CloseWithGraceReturn; | |
export = closeWithGrace; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment