process routes concurrently

This commit is contained in:
Joel Wetzell
2025-12-28 20:42:11 -06:00
parent bd2a68ff6e
commit 59f00c1a32

View File

@@ -131,8 +131,13 @@ func (r *Router) Stop() {
func (r *Router) HandleInput(ctx context.Context, sourceId string, payload any) (bool, []route.RouteIOError) { func (r *Router) HandleInput(ctx context.Context, sourceId string, payload any) (bool, []route.RouteIOError) {
var routeIOErrors []route.RouteIOError var routeIOErrors []route.RouteIOError
routeFound := false routeFound := false
var routeWaitGroup sync.WaitGroup
for routeIndex, routeInstance := range r.RouteInstances { for routeIndex, routeInstance := range r.RouteInstances {
if routeInstance.Input() == sourceId { if routeInstance.Input() == sourceId {
routeWaitGroup.Go(func() {
routeFound = true routeFound = true
routeContext := context.WithValue(ctx, route.SourceContextKey, sourceId) routeContext := context.WithValue(ctx, route.SourceContextKey, sourceId)
@@ -146,12 +151,12 @@ func (r *Router) HandleInput(ctx context.Context, sourceId string, payload any)
Index: routeIndex, Index: routeIndex,
ProcessError: err, ProcessError: err,
}) })
continue return
} }
if payload == nil { if payload == nil {
r.logger.Error("no input after processing", "route", routeIndex, "source", sourceId) r.logger.Error("no input after processing", "route", routeIndex, "source", sourceId)
continue return
} }
outputErrors := r.HandleOutput(routeContext, routeInstance.Output(), payload) outputErrors := r.HandleOutput(routeContext, routeInstance.Output(), payload)
@@ -164,9 +169,11 @@ func (r *Router) HandleInput(ctx context.Context, sourceId string, payload any)
OutputErrors: outputErrors, OutputErrors: outputErrors,
}) })
} }
})
} }
} }
routeWaitGroup.Wait()
return routeFound, routeIOErrors return routeFound, routeIOErrors
} }