commit 5678bec158a3bed7fc2b3c863933f09caf8f3194
parent a7df94e003eedac5cd5eba06ffcb8417c8771316
Author: Matsuda Kenji <info@mtkn.jp>
Date: Mon, 9 Oct 2023 07:57:38 +0900
delete unnecessary code for context
Diffstat:
2 files changed, 1 insertion(+), 30 deletions(-)
diff --git a/client.go b/client.go
@@ -158,6 +158,7 @@ func (c *Client) Version(ctx context.Context, mSize uint32, version string) (Msg
if err != nil {
return nil, fmt.Errorf("add to reqpool: %v", err)
}
+ defer c.rPool.delete(req.tag)
go func() {
select {
case <-ctx.Done():
@@ -170,7 +171,6 @@ func (c *Client) Version(ctx context.Context, mSize uint32, version string) (Msg
case <-ctx.Done():
return nil, ctx.Err()
}
- c.rPool.delete(req.tag)
}
/*
diff --git a/req.go b/req.go
@@ -62,26 +62,6 @@ func (rp *ReqPool) delete(tag uint16) {
delete(rp.m, tag)
}
-type clientReqKeyType int
-var clientReqKey clientReqKeyType
-type keyType int
-const (
- msgKey keyType = iota
- rmsgcKey
-)
-func ctxWithMsgAndRmsgc(ctx context.Context, m Msg) (context.Context, <-chan Msg) {
- rmsgc := make(chan Msg)
- return context.WithValue(context.WithValue(ctx, msgKey, m), rmsgcKey, rmsgc), rmsgc
-}
-func msgFromCtx(ctx context.Context) (Msg, bool) {
- m, ok := ctx.Value(msgKey).(Msg)
- return m, ok
-}
-func rmsgcFromCtx(ctx context.Context) (chan<- Msg, bool) {
- c, ok := ctx.Value(rmsgcKey).(chan Msg)
- return c, ok
-}
-
type clientReq struct {
tag uint16
pool *clientReqPool
@@ -92,15 +72,6 @@ type clientReq struct {
ctxDone <-chan struct{}
}
-func ctxWithClientReq(ctx context.Context, r *clientReq) context.Context {
- return context.WithValue(ctx, clientReqKey, r)
-}
-
-func clientReqFromCtx(ctx context.Context) (*clientReq, bool) {
- r, ok := ctx.Value(clientReqKey).(*clientReq)
- return r, ok
-}
-
type clientReqPool struct {
m map[uint16]*clientReq
lock *sync.Mutex