Skip to content

Instantly share code, notes, and snippets.

@Happytreat
Created January 1, 2021 08:49
Show Gist options
  • Save Happytreat/474bc41b99885c09c9e75057e4518da2 to your computer and use it in GitHub Desktop.
Save Happytreat/474bc41b99885c09c9e75057e4518da2 to your computer and use it in GitHub Desktop.
Reusable Errors
// condRelease releases this connection if the error pointed to by err
// is nil (not an error) or is predefined Reusable error
// The purpose is to not recycle TCP connections that are bad.
func (cn *conn) ConnRelease(err *error) {
if *err == nil || resumableError(*err) {
cn.release()
} else {
cn.nc.Close()
}
}
func resumableError(err error) bool {
switch err {
case ReusableError:
return true
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment