-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix typescript typing, checkout npmignore, bump minor, rebuild
- Loading branch information
Showing
15 changed files
with
28 additions
and
208 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
tests/ | ||
.gitignore | ||
.npmignore | ||
.travis.yml | ||
LICENSE | ||
tslint.json | ||
package-lock.json |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,189 +0,0 @@ | ||
// +----------------------------------------------------------------------+ | ||
// | node-graceful v0.2.2 (https://github.com/mrbar42/node-graceful) | | ||
// | Graceful process exit manager. | | ||
// |----------------------------------------------------------------------| | ||
"use strict"; | ||
|
||
function Graceful() { | ||
// options | ||
this.exitOnDouble = true; | ||
this.timeout = 30000; | ||
|
||
// constants | ||
this.DEADLY_SIGNALS = ["SIGTERM", "SIGINT", "SIGBREAK", "SIGHUP"]; | ||
|
||
// state | ||
this._listeners = Object.create(null); | ||
this.isExiting = false; | ||
} | ||
|
||
Graceful.prototype.on = function (signal, listener, deadly) { | ||
var _this = this; | ||
this._registerSignal(signal); | ||
|
||
this._listeners[signal].push(listener); | ||
|
||
// add signal to deadly list | ||
if (deadly && this.DEADLY_SIGNALS.indexOf(signal) === -1) { | ||
this.DEADLY_SIGNALS.push(signal); | ||
} | ||
|
||
return function () { | ||
return _this.off(signal, listener); | ||
}; | ||
}; | ||
|
||
Graceful.prototype.off = function (signal, listener) { | ||
if (!this._listeners[signal]) return; | ||
|
||
// remove listener if exists | ||
var index = this._listeners[signal].indexOf(listener); | ||
if (index !== -1) this._listeners[signal].splice(index, 1); | ||
|
||
// clear master listener if no listeners left | ||
if (!this._listeners[signal].length) { | ||
this._unregisterSignal(signal); | ||
} | ||
}; | ||
|
||
Graceful.prototype.clear = function (signal) { | ||
var _this = this; | ||
if (signal) { | ||
delete this._listeners[signal]; | ||
this._unregisterSignal(signal); | ||
} else { | ||
Object.keys(this._listeners).forEach(function (sig) { | ||
return _this.clear(signal); | ||
}); | ||
} | ||
}; | ||
|
||
Graceful.prototype.exit = function (code, signal) { | ||
if (typeof code == "number") { | ||
process.exitCode = code; | ||
} | ||
|
||
var simulatedSignal = signal || this.DEADLY_SIGNALS[0]; | ||
|
||
this._processSignal(simulatedSignal); | ||
}; | ||
|
||
Graceful.prototype._registerSignal = function (signal) { | ||
var _this = this; | ||
if (this._listeners[signal]) return; | ||
|
||
this._listeners[signal] = []; | ||
|
||
var handler = function (event) { | ||
return _this._processSignal(signal, event); | ||
}; | ||
|
||
// handle special 'exit' event case | ||
if (signal == "exit") { | ||
this.DEADLY_SIGNALS.forEach(function (deadlySignal) { | ||
return process.on(deadlySignal, handler); | ||
}); | ||
} else { | ||
process.on(signal, handler); | ||
} | ||
|
||
// store handler on listeners array for future ref | ||
this._listeners[signal].__handler__ = handler; | ||
}; | ||
|
||
Graceful.prototype._unregisterSignal = function (signal) { | ||
if (!this._listeners[signal]) return; | ||
|
||
var handler = this._listeners[signal].__handler__; | ||
|
||
// handle special 'exit' event case | ||
if (signal == "exit") { | ||
this.DEADLY_SIGNALS.forEach(function (deadlySignal) { | ||
return process.removeListener(deadlySignal, handler); | ||
}); | ||
} else { | ||
process.removeListener(signal, handler); | ||
} | ||
|
||
delete this._listeners[signal]; | ||
}; | ||
|
||
Graceful.prototype._processSignal = function (signal, event) { | ||
var _this = this; | ||
var deadly = this.DEADLY_SIGNALS.indexOf(signal) != -1; | ||
var listeners = this._listeners[signal] && this._listeners[signal].slice(); | ||
var exitListeners = this._listeners.exit && this._listeners.exit.slice(); | ||
var targetCount = listeners && listeners.length || 0; | ||
|
||
// also include exit listeners if deadly | ||
if (deadly && exitListeners) { | ||
targetCount += exitListeners.length; | ||
} | ||
|
||
// this should never happen | ||
if (!targetCount) { | ||
return process.nextTick(function () { | ||
return _this._killProcess(); | ||
}); | ||
} | ||
|
||
var quit = (function () { | ||
var count = 0; | ||
return function () { | ||
count++; | ||
if (count >= targetCount) { | ||
if (deadly) _this._killProcess(); | ||
} | ||
}; | ||
})(); | ||
|
||
// exec signal specific listeners | ||
if (listeners) { | ||
listeners.forEach(function (listener) { | ||
return _this._invokeListener(listener, quit, event, signal); | ||
}); | ||
} | ||
|
||
|
||
// also invoke exit listeners | ||
if (deadly && exitListeners) { | ||
if (this.isExiting) { | ||
if (this.exitOnDouble) this._killProcess(true); | ||
} else { | ||
this.isExiting = true; | ||
if (parseInt(this.timeout)) { | ||
setTimeout(function () { | ||
return _this._killProcess(true); | ||
}, this.timeout); | ||
} | ||
exitListeners.forEach(function (listener) { | ||
return _this._invokeListener(listener, quit, event, signal); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
Graceful.prototype._killProcess = function (force) { | ||
process.exit(process.exitCode || (force ? 1 : 0)); | ||
}; | ||
|
||
Graceful.prototype._invokeListener = function (listener, quit, event, signal) { | ||
var invoked = false; | ||
// listener specific callback | ||
var done = function () { | ||
if (!invoked) { | ||
invoked = true; | ||
quit(); | ||
} | ||
}; | ||
|
||
var retVal = listener(done, event, signal); | ||
// allow returning a promise | ||
if (retVal && typeof retVal.then === "function" && typeof retVal["catch"] === "function") { | ||
retVal.then(done)["catch"](done); | ||
} | ||
}; | ||
|
||
var graceful = new Graceful(); | ||
module.exports = graceful; | ||
|
||
This file contains 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
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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