Something went wrong. Try again.
sloproxy
Something went wrong. Try again.
711 B · 33 lines
Go
at main
12345678910111213141516171819202122232425262728293031323334package executor
import ( "errors" "io" "sync")
// ExecutionLifecycle owns resources associated with an execution attempt.type ExecutionLifecycle interface { Bind(func() error) error End(string)}
// BindExecutionResource binds a closer to the execution lifecycle.func BindExecutionResource(opts Options, closer io.Closer) error { if opts.ExecutionLifecycle == nil || closer == nil { return nil }
var closeOnce sync.Once var closeErr error closeResource := func() error { closeOnce.Do(func() { closeErr = closer.Close() }) return closeErr } if errBind := opts.ExecutionLifecycle.Bind(closeResource); errBind != nil { return errors.Join(errBind, closeResource()) } return nil}