Skip to content

Commit

Permalink
Merge pull request #241 from bjornbytes/handle-cleanup
Browse files Browse the repository at this point in the history
Cleanup handles properly on exit;
  • Loading branch information
creationix committed Oct 4, 2018
2 parents 85355d5 + 31ea807 commit b7f99e0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions main.lua
Expand Up @@ -26,6 +26,23 @@ local aliases = {
["-h"] = "help",
}
local function exit(status)
uv.walk(function(handle)
if handle then
local function close()
if not handle:is_closing() then handle:close() end
end
if handle.shutdown then
handle:shutdown(close)
else
close()
end
end
end)
uv.run()
os.exit(status)
end
_G.p = require('pretty-print').prettyPrint
local version = require('./package').version
coroutine.wrap(function ()
Expand All @@ -39,7 +56,7 @@ coroutine.wrap(function ()
local success, err = xpcall(function ()
log("lit version", version)
log("luvi version", require('luvi').version)
if command == "version" then os.exit(0) end
if command == "version" then exit(0) end
local path = "./commands/" .. command .. ".lua"
if bundle.stat(path:sub(3)) then
log("command", table.concat(args, " "), "highlight")
Expand All @@ -58,11 +75,11 @@ coroutine.wrap(function ()
if success then
log("done", "success", "success")
print()
os.exit(0)
exit(0)
else
log("fail", err, "failure")
print()
os.exit(-1)
exit(-1)
end
end)()
uv.run()

0 comments on commit b7f99e0

Please sign in to comment.