refactor: rename files into common naming, rename GetId to NextId, document function

This commit is contained in:
2025-08-01 16:42:46 -05:00
parent 55a390e69c
commit 7081d06001
9 changed files with 7 additions and 5 deletions

2
app.go
View File

@@ -370,7 +370,7 @@ func (a *App) Start() {
go runIntervals(a)
// subscribe to state_changed events
id := internal.GetId()
id := internal.NextId()
ws.SubscribeToStateChangedEvents(id, a.wsWriter, a.ctx)
a.entityListenersId = id

View File

View File

View File

View File

@@ -16,7 +16,9 @@ var (
id atomic.Int64 // default value is 0
)
func GetId() int64 {
// NextId returns a unique integer (for the given process), often used for providing a uniquely identifiable
// id for a request. This function is thread-safe.
func NextId() int64 {
return id.Add(1)
}

View File

@@ -23,7 +23,7 @@ type FireEventRequest struct {
// as `event_data`.
func (e Event) Fire(eventType string, eventData ...map[string]any) error {
req := FireEventRequest{
Id: internal.GetId(),
Id: internal.NextId(),
Type: "fire_event",
}

View File

@@ -45,8 +45,8 @@ type BaseServiceRequest struct {
}
func NewBaseServiceRequest(entityId string) BaseServiceRequest {
id := internal.GetId()
bsr := BaseServiceRequest{
id := internal.NextId()
Id: id,
RequestType: "call_service",
}

View File

@@ -140,7 +140,7 @@ func SubscribeToStateChangedEvents(id int64, conn *WebsocketWriter, ctx context.
func SubscribeToEventType(eventType string, conn *WebsocketWriter, ctx context.Context, id ...int64) {
var finalId int64
if len(id) == 0 {
finalId = internal.GetId()
finalId = internal.NextId()
} else {
finalId = id[0]
}