test(utils): 添加事件驱动模型测试

- 在 sqrt_test.go 中添加了 fastSqr1 测试函数,用于测试事件驱动模型
- 新增了 Event 和 Uint32AsyncEvent 类型用于测试
- 更新了 go.work、go.mod 和
This commit is contained in:
2025-08-05 16:10:18 +08:00
parent bbbec5dff0
commit cd7583ba05
32 changed files with 1789 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package events
import (
"context"
)
type EventState struct {
Ctx context.Context
Done chan struct{} `json:"-"`
Error error
}
func NewEventState(ctx context.Context) *EventState {
return &EventState{
Ctx: ctx,
Done: make(chan struct{}),
}
}
func (s *EventState) Close() {
s.Error = s.Ctx.Err()
close(s.Done)
}
type NewOrder struct {
ID int
}
type CreateOrderEvent struct {
NewOrder *NewOrder
ProductIDs []int
State *EventState
}