diff --git a/environment.go b/environment.go index ec412a5..63e95ae 100644 --- a/environment.go +++ b/environment.go @@ -137,11 +137,13 @@ func (this *environment) Del(ctx context.Context, actors ...Actor) error { channels := []<- chan struct { } { } for _, actor := range actors { info := this.info(actor) - if info.done != nil { + if info.stopped != nil { channels = append(channels, info.stopped) } + info.done() } for _, channel := range channels { + if channel == nil { continue } select { case <- channel: case <- ctx.Done(): @@ -250,7 +252,11 @@ func (this *environment) run(actor Actor) { // contains context information info := this.info(actor) ctx := info.ctx - defer close(info.stopped) + defer func() { + if info.stopped != nil { + close(info.stopped) + } + }() switch actor := actor.(type) { case Runnable: