Skip to content

Commit f20bc45

Browse files
hugomrdiassatazor
authored andcommitted
feat: add signal exit (#65)
1 parent 1394ff6 commit f20bc45

4 files changed

Lines changed: 2310 additions & 2204 deletions

File tree

README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,7 @@ Returns a boolean or throws on error.
159159

160160
## Graceful exit
161161

162-
`proper-lockfile` automatically remove locks if the process exists. Though, `SIGINT` and `SIGTERM` signals
163-
are handled differently by `nodejs` in the sense that they do not fire a `exit` event on the `process`.
164-
To avoid this common issue that `CLI` developers have, please do the following:
165-
166-
167-
```js
168-
// Map SIGINT & SIGTERM to process exit
169-
// so that lockfile removes the lockfile automatically
170-
process
171-
.once('SIGINT', () => process.exit(1))
172-
.once('SIGTERM', () => process.exit(1));
173-
```
162+
`proper-lockfile` automatically remove locks if the process exists.
174163

175164

176165
## Tests

lib/lockfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const path = require('path');
44
const fs = require('graceful-fs');
55
const retry = require('retry');
6+
const onExit = require('signal-exit');
67

78
const locks = {};
89

@@ -292,7 +293,7 @@ function getLocks() {
292293

293294
// Remove acquired locks on exit
294295
/* istanbul ignore next */
295-
process.on('exit', () => {
296+
onExit(() => {
296297
for (const file in locks) {
297298
try { locks[file].options.fs.rmdirSync(getLockFile(file)); } catch (e) { /* Empty */ }
298299
}

0 commit comments

Comments
 (0)