mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-30 03:21:47 +08:00
通过反射,改造钩子机制
This commit is contained in:
25
hook_test.go
Normal file
25
hook_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestAddHook(t *testing.T) {
|
||||
t.Run(t.Name(), func(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go AddHook("test", func(a, b int) {
|
||||
fmt.Printf("on test,%d,%d", a, b)
|
||||
})
|
||||
go AddHook("done", wg.Done)
|
||||
TriggerHook("test", 2, 10)
|
||||
<-time.After(time.Millisecond * 100)
|
||||
TriggerHook("test", 1, 12)
|
||||
<-time.After(time.Millisecond * 100)
|
||||
TriggerHook("done")
|
||||
wg.Wait()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user