Skip to content

Commit b9a9ce4

Browse files
abort signal on both beforeExit and exit signals
2 parents 024e3f2 + f52166c commit b9a9ce4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import { randomUUID } from "crypto";
1111
import {normalize as normalizePath} from 'path'
1212
import CONSTANTS from './constants'
1313

14-
process.on('exit', () => {
15-
DBDestroySignal.abort('Process is exiting')
16-
})
17-
1814
export async function createDB(opts?: ServerOptions) {
1915
const defaultOptions: InternalServerOptions = {
2016
dbName: 'dbdata',

src/libraries/AbortSignal.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
const DBDestroySignal = new AbortController();
22

3+
function abortSignal() {
4+
if (!DBDestroySignal.signal.aborted) {
5+
DBDestroySignal.abort('Process is exiting')
6+
}
7+
}
8+
9+
process.on('beforeExit', abortSignal)
10+
process.on('exit', abortSignal)
11+
312
export default DBDestroySignal;

0 commit comments

Comments
 (0)