githublaohu commented on code in PR #803:
URL: https://github.com/apache/rocketmq-client-go/pull/803#discussion_r851025090


##########
internal/request_response_future.go:
##########
@@ -0,0 +1,135 @@
+package internal
+
+import (
+       "context"
+       "fmt"
+       "sync"
+       "time"
+
+       "github.com/patrickmn/go-cache"
+       "github.com/pkg/errors"
+
+       "github.com/apache/rocketmq-client-go/v2/primitive"
+       "github.com/apache/rocketmq-client-go/v2/rlog"
+)
+
+var RequestResponseFutureMap = NewRequestResponseFutureMap()
+
+type requestResponseFutureCache struct {
+       cache *cache.Cache
+}
+
+func NewRequestResponseFutureMap() *requestResponseFutureCache {
+       tmpRrfCache := requestResponseFutureCache{
+               cache: cache.New(5*time.Minute, 10*time.Minute),
+       }
+
+       // OnEvicted delete the timeout RequestResponseFuture, trigger set the 
failure cause.
+       tmpRrfCache.cache.OnEvicted(func(s string, i interface{}) {
+               rrf, ok := i.(*RequestResponseFuture)
+               if !ok {
+                       rlog.Error("convert i to RequestResponseFuture err", 
map[string]interface{}{
+                               "correlationId": s,
+                       })
+                       return
+               }
+               if !rrf.IsTimeout() {
+                       return
+               }
+
+               err := fmt.Errorf("correlationId:%s request timeout, no reply 
message", s)
+               rrf.CauseErr = err
+               rrf.ExecuteRequestCallback()

Review Comment:
   如果异常cache有删除操作,麻烦特地注释下,不是所有人都对cache了解的



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to