Skip to content

Commit

Permalink
Use at_exit handlers where possible to reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
bew committed Dec 20, 2017
1 parent 49028a1 commit 00d23ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/crystal/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ module Crystal
GC.init

remember_blocking_state
at_exit do
STDOUT.flush
STDERR.flush
restore_blocking_state
end

status =
begin
Expand All @@ -56,15 +61,9 @@ module Crystal
1
end

status = AtExitHandlers.run status

ex.inspect_with_backtrace STDERR if ex
STDOUT.flush
STDERR.flush

restore_blocking_state

status
AtExitHandlers.run status
end

# Main method run by all Crystal programs at startup.
Expand Down
2 changes: 0 additions & 2 deletions src/kernel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ end
# Registered `at_exit` procs are executed.
def exit(status = 0) : NoReturn
status = AtExitHandlers.run status
STDOUT.flush
STDERR.flush
Process.exit(status)
end

Expand Down

0 comments on commit 00d23ab

Please sign in to comment.