瀏覽代碼

keep mq updates in a single go func

Abhishek Kondur 2 年之前
父節點
當前提交
504ce7feb9
共有 1 個文件被更改,包括 8 次插入7 次删除
  1. 8 7
      controllers/hosts.go

+ 8 - 7
controllers/hosts.go

@@ -258,13 +258,14 @@ func addHostToNetwork(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 	logger.Log(1, "added new node", newNode.ID.String(), "to host", currHost.Name)
-
-	mq.HostUpdate(&models.HostUpdate{
-		Action: models.JoinHostToNetwork,
-		Host:   *currHost,
-		Node:   *newNode,
-	})
-	go mq.PublishPeerUpdate()
+	go func() {
+		mq.HostUpdate(&models.HostUpdate{
+			Action: models.JoinHostToNetwork,
+			Host:   *currHost,
+			Node:   *newNode,
+		})
+		mq.PublishPeerUpdate()
+	}()
 	logger.Log(2, r.Header.Get("user"), fmt.Sprintf("added host %s to network %s", currHost.Name, network))
 	w.WriteHeader(http.StatusOK)
 }