Remove actors added through Add if they fail to initialize/config
This commit is contained in:
parent
8f8d2e13b3
commit
f97f5010e2
@ -111,6 +111,10 @@ func (this *environment) Done(cause error) {
|
|||||||
// Add implements the package-level function [Add].
|
// Add implements the package-level function [Add].
|
||||||
func (this *environment) Add(ctx context.Context, actors ...Actor) error {
|
func (this *environment) Add(ctx context.Context, actors ...Actor) error {
|
||||||
this.addToSets(actors...)
|
this.addToSets(actors...)
|
||||||
|
cleanUp := func() {
|
||||||
|
this.delFromSets(actors...)
|
||||||
|
}
|
||||||
|
|
||||||
initializable := make([]Initializable, 0, len(actors))
|
initializable := make([]Initializable, 0, len(actors))
|
||||||
for _, actor := range actors {
|
for _, actor := range actors {
|
||||||
if actor, ok := actor.(Initializable); ok {
|
if actor, ok := actor.(Initializable); ok {
|
||||||
@ -122,12 +126,14 @@ func (this *environment) Add(ctx context.Context, actors ...Actor) error {
|
|||||||
if this.flags.crashOnError {
|
if this.flags.crashOnError {
|
||||||
panic(fmt.Sprint(err))
|
panic(fmt.Sprint(err))
|
||||||
}
|
}
|
||||||
|
cleanUp()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, actor := range actors {
|
for _, actor := range actors {
|
||||||
if actor, ok := actor.(Configurable); ok {
|
if actor, ok := actor.(Configurable); ok {
|
||||||
err := actor.Configure(this.conf)
|
err := actor.Configure(this.conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
cleanUp()
|
||||||
return fmt.Errorf (
|
return fmt.Errorf (
|
||||||
"could not apply configuration to %s: %w",
|
"could not apply configuration to %s: %w",
|
||||||
actor.(Actor).Type(), err)
|
actor.(Actor).Type(), err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user