- 在 sqrt_test.go 中添加了 fastSqr1 测试函数,用于测试事件驱动模型 - 新增了 Event 和 Uint32AsyncEvent 类型用于测试 - 更新了 go.work、go.mod 和
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package events
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/badu/bus/test_scenarios/factory-request-reply/inventory"
|
|
"github.com/badu/bus/test_scenarios/factory-request-reply/prices"
|
|
)
|
|
|
|
type InventoryGRPCClientRequestEvent struct {
|
|
wg sync.WaitGroup
|
|
Conn Closer // should be *grpc.ClientConn, but we're avoiding the import
|
|
Client inventory.ServiceClient
|
|
}
|
|
|
|
func NewInventoryGRPCClientRequestEvent() *InventoryGRPCClientRequestEvent {
|
|
result := InventoryGRPCClientRequestEvent{}
|
|
result.wg.Add(1)
|
|
return &result
|
|
}
|
|
|
|
func (i *InventoryGRPCClientRequestEvent) Async() bool {
|
|
return true // this one is async
|
|
}
|
|
|
|
func (i *InventoryGRPCClientRequestEvent) WaitReply() {
|
|
i.wg.Wait()
|
|
}
|
|
|
|
func (i *InventoryGRPCClientRequestEvent) Reply() {
|
|
i.wg.Done()
|
|
}
|
|
|
|
type PricesGRPCClientRequestEvent struct {
|
|
wg sync.WaitGroup
|
|
Conn Closer // should be *grpc.ClientConn, but we're avoiding the import
|
|
Client prices.ServiceClient
|
|
}
|
|
|
|
func NewPricesGRPCClientRequestEvent() *PricesGRPCClientRequestEvent {
|
|
result := PricesGRPCClientRequestEvent{}
|
|
result.wg.Add(1)
|
|
return &result
|
|
}
|
|
|
|
func (p *PricesGRPCClientRequestEvent) WaitReply() {
|
|
p.wg.Wait()
|
|
}
|
|
|
|
func (p *PricesGRPCClientRequestEvent) Reply() {
|
|
p.wg.Done()
|
|
}
|
|
|
|
type Closer interface {
|
|
Close() error
|
|
}
|