Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 27, 2021
1 parent 27afecb commit f14ce4f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const callbacks = new Set();
let called = false;
let registered = false;
let isCalled = false;
let isRegistered = false;

function exit(exit, signal) {
if (called) {
if (isCalled) {
return;
}

called = true;
isCalled = true;

for (const callback of callbacks) {
callback();
Expand All @@ -23,8 +23,8 @@ function exit(exit, signal) {
module.exports = callback => {
callbacks.add(callback);

if (!registered) {
registered = true;
if (!isRegistered) {
isRegistered = true;

process.once('exit', exit);
process.once('SIGINT', exit.bind(null, true, 2));
Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import exitHook = require('.');
import exitHook = require('./index.js');

const unsubscribe = exitHook(() => {});

Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "Run some code when the process exits",
"license": "MIT",
"repository": "sindresorhus/exit-hook",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=6"
Expand Down
4 changes: 0 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ The `process.on('exit')` event doesn't catch all the ways a process can exit.

This package is useful for cleaning up before exiting.


## Install

```
$ npm install exit-hook
```


## Usage

```js
Expand Down Expand Up @@ -44,7 +42,6 @@ const unsubscribe = exitHook(() => {});
unsubscribe();
```


## API

### exitHook(callback)
Expand All @@ -57,7 +54,6 @@ Type: `Function`

The callback to execute when the process exits.


---

<div align="center">
Expand Down

0 comments on commit f14ce4f

Please sign in to comment.