Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
29642fc
update jsdoc
silkentrance Feb 3, 2020
7b77436
add changelog
silkentrance Feb 3, 2020
19febe2
remove SIGINT listener, simplify EXIT listener
silkentrance Feb 3, 2020
05d1b43
update jsdoc
silkentrance Feb 3, 2020
78c72ef
fix tests, remove obsolete tests, add missing SIGINT handlers
silkentrance Feb 3, 2020
f3005fc
update jsdoc
silkentrance Feb 3, 2020
327eb83
include node v13 in builds
silkentrance Feb 3, 2020
bcb43a0
update documentation
silkentrance Feb 3, 2020
5195a26
add contributors to package.json
silkentrance Feb 3, 2020
b63cb58
fix #213 tmp.file must not unlink file when discarding the file descr…
silkentrance Feb 3, 2020
1746331
update jsdoc
silkentrance Feb 3, 2020
9500e10
update jsdoc
silkentrance Feb 4, 2020
7ee5bdd
fix #156 #207 #218 #176 #236 #237 #238
silkentrance Feb 7, 2020
ba70579
code cleanup - remove reference to process.bindings
silkentrance Feb 7, 2020
f3c3ab8
code cleanup - replace var by let or const
silkentrance Feb 7, 2020
be9df6f
code cleanup - prefix private functions with an underscore, move all …
silkentrance Feb 7, 2020
5cfca26
limit minimum node version to v8.17.0 - otherwise eslint will fail
silkentrance Feb 7, 2020
4a144b4
code cleanup - remove documentation on old node version error code an…
silkentrance Feb 7, 2020
0664e9a
code cleanup - better error handling
silkentrance Feb 7, 2020
486205b
fix #240
silkentrance Feb 7, 2020
5110e94
fix regression - os.constants.errno are different from what WIN32 act…
silkentrance Feb 7, 2020
2c80c6d
regression - tmp name included a trailing hyphen if no postfix was given
silkentrance Feb 8, 2020
c7028f2
cleanup code
silkentrance Apr 8, 2020
c8823e5
fix #246: remove any double quotes or single quotes from os.tmpdir al…
silkentrance Apr 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove SIGINT listener, simplify EXIT listener
  • Loading branch information
silkentrance committed Feb 3, 2020
commit 19febe21d9a7d20142bb54860d5da04fd5965af9
95 changes: 3 additions & 92 deletions lib/tmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const

EXIT = 'exit',

SIGINT = 'SIGINT',

// this will hold the objects need to be removed on exit
_removeObjects = [],

Expand Down Expand Up @@ -498,6 +496,7 @@ function _prepareRemoveCallback(removeFunction, fileOrDirName, sync, cleanupCall
* @private
*/
function _garbageCollector() {
console.log(_gracefulCleanup);
/* istanbul ignore else */
if (!_gracefulCleanup) return;

Expand Down Expand Up @@ -578,96 +577,8 @@ function _getTmpDir() {
return os.tmpdir();
}

/**
* If there are multiple different versions of tmp in place, make sure that
* we recognize the old listeners.
*
* @param {Function} listener
* @private
* @returns {Boolean} true whether listener is a legacy listener
*/
function _is_legacy_listener(listener) {
return (listener.name === '_exit' || listener.name === '_uncaughtExceptionThrown')
&& listener.toString().indexOf('_garbageCollector();') > -1;
}

/**
* Safely install SIGINT listener.
*
* NOTE: this will only work on OSX and Linux.
*
* @private
*/
function _safely_install_sigint_listener() {

const listeners = process.listeners(SIGINT);
const existingListeners = [];
for (let i = 0, length = listeners.length; i < length; i++) {
const lstnr = listeners[i];
/* istanbul ignore else */
if (lstnr.name === '_tmp$sigint_listener') {
existingListeners.push(lstnr);
process.removeListener(SIGINT, lstnr);
}
}
process.on(SIGINT, function _tmp$sigint_listener(doExit) {
for (let i = 0, length = existingListeners.length; i < length; i++) {
// let the existing listener do the garbage collection (e.g. jest sandbox)
try {
existingListeners[i](false);
} catch (err) {
// ignore
}
}
try {
// force the garbage collector even it is called again in the exit listener
_garbageCollector();
} finally {
if (!!doExit) {
process.exit(0);
}
}
});
}

/**
* Safely install process exit listener.
*
* @private
*/
function _safely_install_exit_listener() {
const listeners = process.listeners(EXIT);

// collect any existing listeners
const existingListeners = [];
for (let i = 0, length = listeners.length; i < length; i++) {
const lstnr = listeners[i];
/* istanbul ignore else */
// TODO: remove support for legacy listeners once release 1.0.0 is out
if (lstnr.name === '_tmp$safe_listener' || _is_legacy_listener(lstnr)) {
// we must forget about the uncaughtException listener, hopefully it is ours
if (lstnr.name !== '_uncaughtExceptionThrown') {
existingListeners.push(lstnr);
}
process.removeListener(EXIT, lstnr);
}
}
// TODO: what was the data parameter good for?
process.addListener(EXIT, function _tmp$safe_listener(data) {
for (let i = 0, length = existingListeners.length; i < length; i++) {
// let the existing listener do the garbage collection (e.g. jest sandbox)
try {
existingListeners[i](data);
} catch (err) {
// ignore
}
}
_garbageCollector();
});
}

_safely_install_exit_listener();
_safely_install_sigint_listener();
// Install process exit listener
process.addListener(EXIT, _garbageCollector);

/**
* Configuration options.
Expand Down