AlexStocks commented on code in PR #1029:
URL: https://github.com/apache/dubbo-go-samples/pull/1029#discussion_r2780310710


##########
config_center/nacos/go-server/cmd/main.go:
##########
@@ -123,3 +123,42 @@ func main() {
                logger.Error(err)
        }
 }
+
+func publishAndWaitConfig(
+       configClient config_client.IConfigClient,
+       dataID string,
+       group string,
+       content string,
+       timeout time.Duration,
+       pollInterval time.Duration,
+) error {
+       success, err := configClient.PublishConfig(vo.ConfigParam{
+               DataId:  dataID,
+               Group:   group,
+               Content: content,
+       })
+       if err != nil {
+               return err
+       }
+       if !success {
+               return fmt.Errorf("publish config failed")
+       }
+
+       deadline := time.Now().Add(timeout)
+       for {
+               current, err := configClient.GetConfig(vo.ConfigParam{
+                       DataId: dataID,
+                       Group:  group,
+               })
+               if err == nil && strings.TrimSpace(current) == 
strings.TrimSpace(content) {
+                       return nil
+               }
+               if time.Now().After(deadline) {
+                       if err != nil {
+                               return err
+                       }
+                       return fmt.Errorf("wait for config center timeout")
+               }
+               time.Sleep(pollInterval)
+       }
+}

Review Comment:
   @Rynzie02 copilot 这个建议考虑下?



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to