Skip to content

Instantly share code, notes, and snippets.

@qbig
Created August 10, 2018 02:37
Show Gist options
  • Select an option

  • Save qbig/6d17e264013096fbd2a3550d6b5b19d8 to your computer and use it in GitHub Desktop.

Select an option

Save qbig/6d17e264013096fbd2a3550d6b5b19d8 to your computer and use it in GitHub Desktop.
Panic and recover
func server(workChan <-chan *Work) {
    for work := range workChan {
        go safelyDo(work)
    }
}

func safelyDo(work *Work) {
    defer func() {
        if err := recover(); err != nil {
            log.Println("work failed:", err)
        }
    }()
    do(work)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment