mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Fix quit command to work gracefully
This commit is contained in:
parent
259b3dca1b
commit
1c64646393
@ -25,9 +25,8 @@ var Command = function(params,commander,callback) {
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
// The Node.js docs are very clear that exiting in this way can be dangerous because pending I/O is cancelled.
|
||||
// TODO: stop the server listeners explicitly so that Node.js will exit the process naturally.
|
||||
process.exit();
|
||||
// We don't actually quit, we just issue the "th-quit" hook to give listeners a chance to exit
|
||||
$tw.hooks.invokeHook("th-quit");
|
||||
return null;
|
||||
};
|
||||
|
||||
|
@ -359,6 +359,11 @@ Server.prototype.listen = function(port,host,prefix) {
|
||||
}
|
||||
// Display the port number after we've started listening (the port number might have been specified as zero, in which case we will get an assigned port)
|
||||
server.on("listening",function() {
|
||||
// Stop listening when we get the "th-quit" hook
|
||||
$tw.hooks.addHook("th-quit",function() {
|
||||
server.close();
|
||||
});
|
||||
// Log listening details
|
||||
var address = server.address(),
|
||||
url = self.protocol + "://" + (address.family === "IPv6" ? "[" + address.address + "]" : address.address) + ":" + address.port + prefix;
|
||||
$tw.utils.log("Serving on " + url,"brown/orange");
|
||||
|
@ -466,6 +466,11 @@ Server.prototype.listen = function(port,host,prefix,options) {
|
||||
});
|
||||
// Display the port number after we've started listening (the port number might have been specified as zero, in which case we will get an assigned port)
|
||||
server.on("listening",function() {
|
||||
// Stop listening when we get the "th-quit" hook
|
||||
$tw.hooks.addHook("th-quit",function() {
|
||||
server.close();
|
||||
});
|
||||
// Log listening details
|
||||
var address = server.address(),
|
||||
url = self.protocol + "://" + (address.family === "IPv6" ? "[" + address.address + "]" : address.address) + ":" + address.port + prefix;
|
||||
$tw.utils.log("Serving on " + url,"brown/orange");
|
||||
|
Loading…
Reference in New Issue
Block a user