goext/exerr/listener.go

38 lines
597 B
Go
Raw Normal View History

2023-02-08 18:45:31 +01:00
package exerr
2023-02-15 16:04:19 +01:00
import (
"sync"
)
2023-02-08 18:45:31 +01:00
type Method string
const (
MethodOutput Method = "OUTPUT"
MethodPrint Method = "PRINT"
MethodBuild Method = "BUILD"
MethodFatal Method = "FATAL"
)
2023-02-15 16:04:19 +01:00
type Listener = func(method Method, v ExErr)
2023-02-08 18:45:31 +01:00
var listenerLock = sync.Mutex{}
var listener = make([]Listener, 0)
func RegisterListener(l Listener) {
listenerLock.Lock()
defer listenerLock.Unlock()
listener = append(listener, l)
}
func (b *Builder) CallListener(m Method) {
valErr := b.toBMError()
listenerLock.Lock()
defer listenerLock.Unlock()
for _, v := range listener {
v(m, valErr)
}
}