You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another example would be the following code sample in the same article:
funcSafeClose(chchanT) (justClosedbool) {
deferfunc() {
ifrecover() !=nil {
// The return result can be altered// in a defer function call.justClosed=false
}
}()
// assume ch != nil here.close(ch) // panic if ch is closedreturntrue// <=> justClosed = true; return
}
That could be rewritten to:
funcSafeClose[Tany](chchanT) (justClosedbool) {
deferfunc() {
ifrecover() !=nil {
// The return result can be altered// in a defer function call.justClosed=false
}
}()
// assume ch != nil here.close(ch) // panic if ch is closedreturntrue// <=> justClosed = true; return
}
This is just an idea, I can see points being made to either accept it or not, so I'm just leaving it here in case you find it useful 🙂
The text was updated successfully, but these errors were encountered:
@GCrispino
Thanks for the suggestion. I think it is good and would be perfect when Go custom generics are used more popularly later.
At the moment, I don't want the generic thing distract reader's attentions.
Hello everybody!
Now that we have generics, I believe we could leverage them in code examples like the below, in the "How to Gracefully Close Channels" article:
This could be rewritten to:
Another example would be the following code sample in the same article:
That could be rewritten to:
This is just an idea, I can see points being made to either accept it or not, so I'm just leaving it here in case you find it useful 🙂
The text was updated successfully, but these errors were encountered: