Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
33
backend/sdk/cliproxy/executor/lifecycle.go
Normal file
33
backend/sdk/cliproxy/executor/lifecycle.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package 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
|
||||
}
|
||||
Loading…
Reference in a new issue