Exposes Module.IsClosed to prevent calling functions when closed (#1573)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
Crypt Keeper
2023-07-10 15:32:51 +08:00
committed by GitHub
parent 15fa5c4de5
commit 326c267726
6 changed files with 83 additions and 35 deletions

View File

@@ -106,6 +106,11 @@ func (m *ModuleInstance) CloseWithExitCode(ctx context.Context, exitCode uint32)
return m.ensureResourcesClosed(ctx)
}
// IsClosed implements the same method as documented on api.Module.
func (m *ModuleInstance) IsClosed() bool {
return atomic.LoadUint64(&m.Closed) != 0
}
func (m *ModuleInstance) closeWithExitCodeWithoutClosingResource(exitCode uint32) (err error) {
if !m.setExitCode(exitCode, exitCodeFlagResourceNotClosed) {
return nil // not an error to have already closed