Adapt With Close

This commit is contained in:
mr
2026-03-12 16:20:47 +01:00
parent ad29297377
commit a11d764729
5 changed files with 30 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"slices"
"sync"
oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/models/resources"
@@ -18,12 +19,18 @@ var ressourceCols = []oclib.LibDataEnum{
oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE),
}
var SearchMu sync.RWMutex
var SearchStream = map[string]chan resources.ResourceInterface{}
func EmitNATS(user string, groups []string, message tools.PropalgationMessage) {
b, _ := json.Marshal(message)
if message.Action == tools.PB_SEARCH {
SearchStream[user] = make(chan resources.ResourceInterface, 128)
switch message.Action {
case tools.PB_SEARCH:
if slices.Contains(ressourceCols, oclib.LibDataEnum(message.DataType)) {
SearchMu.Lock()
SearchStream[user] = make(chan resources.ResourceInterface, 128)
SearchMu.Unlock()
}
}
tools.NewNATSCaller().SetNATSPub(tools.PROPALGATION_EVENT, tools.NATSResponse{
FromApp: "oc-catalog",
@@ -62,7 +69,9 @@ func ListenNATS() {
p, err := resources.ToResource(int(resp.Datatype), resp.Payload)
if err == nil {
fmt.Println("SearchStream", p)
SearchStream[resp.User] <- p // TODO when do we update it in our catalog ?
SearchMu.Lock()
SearchStream[resp.User] <- p // TODO when do we update it in our catalog ?*
SearchMu.Unlock()
}
},
})