From dd49b2ef9eadf3432557577e14a6e423e94b88a5 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Sat, 15 Jun 2019 10:56:38 +0000 Subject: [PATCH] =?UTF-8?q?pkg:=20atexit:=20=E5=A2=9E=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=B1=BB=E5=9E=8Bprio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/util/atexit/atexit.go | 13 +++++++------ pkg/util/atexit/const.go | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/util/atexit/atexit.go b/pkg/util/atexit/atexit.go index df6157fa9c..20d20a065c 100644 --- a/pkg/util/atexit/atexit.go +++ b/pkg/util/atexit/atexit.go @@ -32,14 +32,14 @@ type ExitHandlerFunc func(ExitHandler) // Prio at exit time. Handler func will receive a copy of the ExitHandler // struct previously registered type ExitHandler struct { - Prio int + Prio Prio Reason string Func ExitHandlerFunc Value interface{} } var ( - handlers = map[int][]ExitHandler{} + handlers = map[Prio][]ExitHandler{} handlersLock = &sync.Mutex{} once = &sync.Once{} ) @@ -79,12 +79,13 @@ func Handle() { handlersLock.Lock() defer handlersLock.Unlock() - prios := make([]int, 0, len(handlers)) + ints := make([]int, 0, len(handlers)) for prio := range handlers { - prios = append(prios, prio) + ints = append(ints, int(prio)) } - sort.Ints(prios) - for _, prio := range prios { + sort.Ints(ints) + for _, i := range ints { + prio := Prio(i) ehs := handlers[prio] for _, eh := range ehs { print("atexit: prio=", prio, ", reason=", eh.Reason, "\n") diff --git a/pkg/util/atexit/const.go b/pkg/util/atexit/const.go index 0bb318ebef..5584f2a431 100644 --- a/pkg/util/atexit/const.go +++ b/pkg/util/atexit/const.go @@ -14,7 +14,9 @@ package atexit +type Prio int + const ( - PRIO_LOG_OTHER = 20000 - PRIO_LOG_CLOSE = 40000 + PRIO_LOG_OTHER Prio = 20000 + PRIO_LOG_CLOSE = 40000 )