modelRT/pool/component_chan_set.go

46 lines
1.1 KiB
Go
Raw Normal View History

package pool
import (
"context"
"fmt"
"sync"
"modelRT/config"
)
func init() {
globalComponentChanSet = &ComponentChanSet{
AnchorChans: make([]chan config.AnchorParamConfig, 100),
}
}
var (
globalComponentChanMap sync.Map
globalComponentChanSet *ComponentChanSet
)
// ComponentChanSet defines component anchor real time data process channel set
type ComponentChanSet struct {
sync.RWMutex
AnchorChans []chan config.AnchorParamConfig
}
func GetAnchorParamChan(ctx context.Context, componentUUID string) (chan config.AnchorParamConfig, error) {
paramChan, ok := globalComponentChanMap.Load(componentUUID)
if !ok {
return CreateNewAnchorParamChan(ctx, componentUUID), nil
}
anchorParamChan, ok := paramChan.(chan config.AnchorParamConfig)
if !ok {
return nil, fmt.Errorf("conversion component anchor param chan type failed for componentUUID: %s", componentUUID)
}
return anchorParamChan, nil
}
func CreateNewAnchorParamChan(ctx context.Context, componentUUID string) chan config.AnchorParamConfig {
anchorParamChan := make(chan config.AnchorParamConfig, 100)
globalComponentChanMap.Store(componentUUID, anchorParamChan)
return anchorParamChan
}