Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Go ¶
Go launches a goroutine with panic recovery and optional context modifications. The provided function f is executed in a new goroutine with the given context. Any panics in the goroutine will be caught and handled by the registered panic handler.
Example usage:
Go(ctx, func(ctx context.Context) { // Your goroutine logic here }, WithTimeout(5*time.Second))
func RegisterPanicHandler ¶
RegisterPanicHandler sets a custom handler function for panics that occur in goroutines started by Go(). The handler receives the context and the error that caused the panic.
If no handler is registered, panics will be propagated normally.
func WG ¶
WG creates a new wait group with context support. It combines the functionality of sync.WaitGroup with context cancellation. The returned wait group will be cancelled when the provided context is cancelled.
Example usage:
wg := WG(ctx) for i := 0; i < 5; i++ { wg.Go(func(ctx context.Context) { // Your concurrent work here }) } wg.Wait() // Wait for all goroutines to complete
Types ¶
type GoOption ¶
GoOption represents a configuration option for the Go function. It receives a context and returns a modified context along with a cleanup function.
func WithNoCancel ¶ added in v1.1.5
func WithNoCancel() GoOption
WithNoCancel returns a GoOption that creates a context that cannot be cancelled. This is useful when you want the goroutine to complete regardless of the parent context's cancellation.
func WithTimeout ¶
WithTimeout returns a GoOption that adds a timeout to the context. The goroutine will be cancelled after the specified duration.