diff --git a/module.go b/module.go index e1a6d196..f3dce971 100644 --- a/module.go +++ b/module.go @@ -155,6 +155,7 @@ func (m *module[T]) register(function *function[T]) { func (m *module[T]) cleanup() { m.function = nil m.template.runtime.activeModulesMu.Lock() + // m.instantiatedModule.CloseWithExitCode(m.template.runtime.config.context, 0) delete(m.template.runtime.activeModules, m.instantiatedModule.Name()) m.template.runtime.activeModulesMu.Unlock() } diff --git a/scale.go b/scale.go index 5f9b214f..1e5255c3 100644 --- a/scale.go +++ b/scale.go @@ -70,6 +70,15 @@ func (r *Scale[T]) Instance(next ...Next[T]) (*Instance[T], error) { return newInstance(r.config.context, r, next...) } +func (r *Scale[T]) Clear() { + for key := range r.activeModules { + r.activeModules[key].instantiatedModule.CloseWithExitCode(r.config.context, 0) + delete(r.activeModules, key) + } + + r.activeModules = make(map[string]*module[T]) +} + // Reset any extensions between executions. func (r *Scale[T]) resetExtensions() { for _, ext := range r.config.extensions {