2023-02-15 16:04:19 +01:00
|
|
|
package exerr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Method string
|
|
|
|
|
|
|
|
const (
|
|
|
|
MethodOutput Method = "OUTPUT"
|
|
|
|
MethodPrint Method = "PRINT"
|
|
|
|
MethodBuild Method = "BUILD"
|
|
|
|
MethodFatal Method = "FATAL"
|
|
|
|
)
|
|
|
|
|
2023-07-24 10:42:39 +02:00
|
|
|
type Listener = func(method Method, v *ExErr)
|
2023-02-15 16:04:19 +01:00
|
|
|
|
|
|
|
var listenerLock = sync.Mutex{}
|
|
|
|
var listener = make([]Listener, 0)
|
|
|
|
|
|
|
|
func RegisterListener(l Listener) {
|
|
|
|
listenerLock.Lock()
|
|
|
|
defer listenerLock.Unlock()
|
|
|
|
|
|
|
|
listener = append(listener, l)
|
|
|
|
}
|
|
|
|
|
2024-01-07 04:01:13 +01:00
|
|
|
func (ee *ExErr) CallListener(m Method) {
|
2023-02-15 16:04:19 +01:00
|
|
|
listenerLock.Lock()
|
|
|
|
defer listenerLock.Unlock()
|
|
|
|
|
|
|
|
for _, v := range listener {
|
2024-01-07 04:01:13 +01:00
|
|
|
v(m, ee)
|
2023-02-15 16:04:19 +01:00
|
|
|
}
|
|
|
|
}
|