From aa4a8e7f7ec8511f6835ba7ecaa168449723b445 Mon Sep 17 00:00:00 2001 From: Michael Street <5597260+MStreet3@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:41:28 +0200 Subject: [PATCH] chore(syncer): modify engine registry api --- .../workflows/syncer/engine_registry.go | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/services/workflows/syncer/engine_registry.go b/core/services/workflows/syncer/engine_registry.go index 1d32dcf4a66..6dd54794e8b 100644 --- a/core/services/workflows/syncer/engine_registry.go +++ b/core/services/workflows/syncer/engine_registry.go @@ -26,26 +26,26 @@ func (r *engineRegistry) Add(id string, engine *workflows.Engine) { } // Get retrieves an engine from the registry. -func (r *engineRegistry) Get(id string) *workflows.Engine { +func (r *engineRegistry) Get(id string) (*workflows.Engine, error) { r.mu.RLock() defer r.mu.RUnlock() - return r.engines[id] + engine, found := r.engines[id] + if !found { + return nil, errors.New("engine not found") + } + return engine, nil } -// Remove removes an engine from the registry. -func (r *engineRegistry) Remove(id string) error { +// Pop removes an engine from the registry and returns the engine if found. +func (r *engineRegistry) Pop(id string) (*workflows.Engine, error) { r.mu.Lock() defer r.mu.Unlock() engine, ok := r.engines[id] if !ok { - return errors.New("remove failed: engine not found") - } - err := engine.Close() - if err != nil { - return err + return nil, errors.New("remove failed: engine not found") } delete(r.engines, id) - return nil + return engine, nil } // Close closes all engines in the registry.