1 Star 0 Fork 0

simple/simple.io

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
boot_client.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
simple 提交于 2024-11-17 21:34 . feat(event): RegisterPlus注册处理器
package event
import (
"context"
"time"
)
type BootClient struct {
*Event
ctx context.Context
cancel context.CancelFunc
}
func NewBootClient() *BootClient {
return &BootClient{Event: NewEvent()}
}
func NewBootClientContext(ctx context.Context) *BootClient {
return &BootClient{ctx: ctx}
}
func (b *BootClient) CancelFunc() {
if b.cancel != nil {
b.cancel()
}
}
func (b *BootClient) Dial(network string, addr string) (StarterClient, error) {
return b.DialTimeout(network, addr, time.Second*30)
}
func (b *BootClient) DialTimeout(network string, addr string, timeout time.Duration) (StarterClient, error) {
client := newStarterClient(network, b.Event, b.ctx)
if _, err := client.DialTimeout(addr, timeout); err != nil {
return nil, err
}
return client, nil
}
func (b *BootClient) DialTcp(addr string) (StarterClient, error) {
return b.DialTimeout("tcp", addr, time.Second*30)
}
func (b *BootClient) DialTcpTimeout(addr string, timeout time.Duration) (StarterClient, error) {
return b.DialTimeout("tcp", addr, timeout)
}
func (b *BootClient) DialUdp(addr string) (StarterClient, error) {
return b.DialTimeout("udp", addr, time.Second*30)
}
func (b *BootClient) DialUdpTimeout(addr string, timeout time.Duration) (StarterClient, error) {
return b.DialTimeout("udp", addr, timeout)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/simple-set/simple.io.git
git@gitee.com:simple-set/simple.io.git
simple-set
simple.io
simple.io
v1.5.3

搜索帮助