Skip to content

Commit

Permalink
remove StopSignal, as runtime.Goexit does the same thing
Browse files Browse the repository at this point in the history
  • Loading branch information
taowen committed Mar 6, 2018
1 parent 797cd41 commit bacd9c7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions unbounded_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ var HandlePanic = func(recovered interface{}, funcName string) {
ErrorLogger.Println(string(debug.Stack()))
}

// StopSignal will not be recovered, will propagate to upper level goroutine
const StopSignal = "STOP!"

// UnboundedExecutor is a executor without limits on counts of alive goroutines
// it tracks the goroutine started by it, and can cancel them when shutdown
type UnboundedExecutor struct {
Expand Down Expand Up @@ -62,16 +59,18 @@ func (executor *UnboundedExecutor) Go(handler func(ctx context.Context)) {
go func() {
defer func() {
recovered := recover()
if recovered != nil && recovered != StopSignal {
// if you want to quit a goroutine without trigger HandlePanic
// use runtime.Goexit() to quit
if recovered != nil {
if executor.HandlePanic == nil {
HandlePanic(recovered, funcName)
} else {
executor.HandlePanic(recovered, funcName)
}
}
executor.activeGoroutinesMutex.Lock()
defer executor.activeGoroutinesMutex.Unlock()
executor.activeGoroutines[startFrom] -= 1
executor.activeGoroutinesMutex.Unlock()
}()
handler(executor.ctx)
}()
Expand Down

0 comments on commit bacd9c7

Please sign in to comment.