I am in a long running cancellable function that has a forever-loop.
I need to check if context is closed.
go func(){
for {
if ctx.Err() != nil { return }
// do work
}
}()
vs
go func(){
for {
select {
case <-ctx.Done():
return
default:
}
// do work
}
}()
Is there a difference between the two?
I am guessing checking ctx.Err() is safe for concurrent-access https://golang.org/src/context/context.go#L370 so they seem identical, given a closed context will always have Err set.