init repo
This commit is contained in:
27
invoker.go
Normal file
27
invoker.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package actor
|
||||
|
||||
import "runtime/debug"
|
||||
|
||||
type invoker[T any] struct {
|
||||
handler func(T)
|
||||
onPanic func(T, any, []byte)
|
||||
}
|
||||
|
||||
func (i *invoker[T]) receive(message T) {
|
||||
completed := false
|
||||
defer func() {
|
||||
if !completed {
|
||||
value := recover()
|
||||
if i.onPanic != nil {
|
||||
i.reportPanic(message, value, debug.Stack())
|
||||
}
|
||||
}
|
||||
}()
|
||||
i.handler(message)
|
||||
completed = true
|
||||
}
|
||||
|
||||
func (i *invoker[T]) reportPanic(message T, value any, stack []byte) {
|
||||
defer func() { _ = recover() }()
|
||||
i.onPanic(message, value, stack)
|
||||
}
|
||||
Reference in New Issue
Block a user