test(utils): 添加事件驱动模型测试
- 在 sqrt_test.go 中添加了 fastSqr1 测试函数,用于测试事件驱动模型 - 新增了 Event 和 Uint32AsyncEvent 类型用于测试 - 更新了 go.work、go.mod 和
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package events
|
||||
|
||||
type RequestEvent[T any] struct {
|
||||
Payload T
|
||||
Callback func() (*T, error)
|
||||
Done chan struct{}
|
||||
}
|
||||
|
||||
func NewRequestEvent[T any](payload T) *RequestEvent[T] {
|
||||
return &RequestEvent[T]{
|
||||
Payload: payload,
|
||||
Done: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (i *RequestEvent[T]) Async() bool {
|
||||
return true // this one is async
|
||||
}
|
||||
Reference in New Issue
Block a user