@@ -936,7 +936,7 @@ func (conn *Connection) newFuture(req Request) (fut *Future) {
936936 ErrRateLimited ,
937937 "Request is rate limited on client" ,
938938 }
939- fut .done = nil
939+ fut .finish ()
940940 return
941941 }
942942 }
@@ -950,23 +950,23 @@ func (conn *Connection) newFuture(req Request) (fut *Future) {
950950 ErrConnectionClosed ,
951951 "using closed connection" ,
952952 }
953- fut .done = nil
953+ fut .finish ()
954954 shard .rmut .Unlock ()
955955 return
956956 case connDisconnected :
957957 fut .err = ClientError {
958958 ErrConnectionNotReady ,
959959 "client connection is not ready" ,
960960 }
961- fut .done = nil
961+ fut .finish ()
962962 shard .rmut .Unlock ()
963963 return
964964 case connShutdown :
965965 fut .err = ClientError {
966966 ErrConnectionShutdown ,
967967 "server shutdown in progress" ,
968968 }
969- fut .done = nil
969+ fut .finish ()
970970 shard .rmut .Unlock ()
971971 return
972972 }
@@ -995,7 +995,7 @@ func (conn *Connection) newFuture(req Request) (fut *Future) {
995995 runtime .Gosched ()
996996 select {
997997 case conn .rlimit <- struct {}{}:
998- case <- fut .done :
998+ case <- fut .WaitChan () :
999999 if fut .err == nil {
10001000 panic ("fut.done is closed, but err is nil" )
10011001 }
@@ -1009,12 +1009,12 @@ func (conn *Connection) newFuture(req Request) (fut *Future) {
10091009// is "done" before the response is come.
10101010func (conn * Connection ) contextWatchdog (fut * Future , ctx context.Context ) {
10111011 select {
1012- case <- fut .done :
1012+ case <- fut .WaitChan () :
10131013 case <- ctx .Done ():
10141014 }
10151015
10161016 select {
1017- case <- fut .done :
1017+ case <- fut .WaitChan () :
10181018 return
10191019 default :
10201020 conn .cancelFuture (fut , fmt .Errorf ("context is done (request ID %d): %w" ,
@@ -1036,7 +1036,8 @@ func (conn *Connection) send(req Request, streamId uint64) *Future {
10361036 conn .incrementRequestCnt ()
10371037
10381038 fut := conn .newFuture (req )
1039- if fut .done == nil {
1039+
1040+ if fut .finished {
10401041 conn .decrementRequestCnt ()
10411042 return fut
10421043 }
@@ -1059,12 +1060,12 @@ func (conn *Connection) putFuture(fut *Future, req Request, streamId uint64) {
10591060 shardn := fut .requestId & (conn .opts .Concurrency - 1 )
10601061 shard := & conn .shard [shardn ]
10611062 shard .bufmut .Lock ()
1062- select {
1063- case <- fut .done :
1063+
1064+ if fut .finished {
10641065 shard .bufmut .Unlock ()
10651066 return
1066- default :
10671067 }
1068+
10681069 firstWritten := shard .buf .Len () == 0
10691070 if shard .buf .Cap () == 0 {
10701071 shard .buf .b = make ([]byte , 0 , 128 )
0 commit comments