Categorygithub.com/aarif123456/safegoroutines
module
0.0.0-20230924204807-78d3f23941b9
Repository: https://github.com/aarif123456/safegoroutines.git
Documentation: pkg.go.dev

# README

safegoroutine

safegoroutine is a linter that ensures every Goroutine is has a defer to catch it. This is required because recover handler are not inherited by child Goroutines in Go.

In it's current state I personally wouldn't use it, since it gives too many false positives.

Instead I would recommend creating a central function to launch Goroutine e.g.

// Go safely launches a Goroutine, so that a panic doesn't bring down the host.
func Go(f func()) {
  go func() {
	defer func() {
	  if err := recover(); err != nil {
		// TODO: handle error
	  }
	}()

	f()
  }()
}

// CtxGo safely launches a Goroutine, so that a panic doesn't bring down the host.
// The context is used to improve our observability.
func CtxGo(ctx context.Context, f func()) {
	go func() {
	defer func() {
	  if err := recover(); err != nil {
		// TODO: handle error
	  }
	}()
	f()
  }()
}

# Packages

No description provided by the author
No description provided by the author