addQuitProc now works with closures, and c, js(node/browser) backend; fix some bugs in testament (#14342)

* make addQuitProc great again

* fix bugs in testament

* fix test

* change 2016 => 2020

* addQuitProc => addExitProc + locks

* move to std/exitprocs
This commit is contained in:
Timothee Cour 2020-06-16 02:43:48 -07:00 • committed by GitHub
commit dfe51d10a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 117 additions and 44 deletions

View file

@ -1,28 +0,0 @@
#
#
# Nim's Runtime Library
# (c) Copyright 2016 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## ``system.addQuitProc`` is nice and very useful but due to its C-based
## implementation it doesn't support closures which limits its usefulness.
## This module fixes this. Later versions of this module will also
## support the JavaScript backend.
var
gClosures: seq[proc () {.closure.}]
proc callClosures() {.noconv.} =
for i in countdown(gClosures.len-1, 0):
gClosures[i]()
proc addQuitClosure*(cl: proc () {.closure.}) =
## Like ``system.addQuitProc`` but it supports closures.
if gClosures.len == 0:
addQuitProc(callClosures)
gClosures = @[cl]
else:
gClosures.add(cl)