goutil

package
v1.2.0-rc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OnPanic = func(r interface{}) {
	syslog.Errorf("panic: %v\n%s", r, debug.Stack())
}

OnPanic is a global callback function triggered when a panic occurs.

Functions

This section is empty.

Types

type Status

type Status struct {
	// contains filtered or unexported fields
}

Status provides a mechanism to wait for a goroutine to finish.

func Go

func Go(ctx context.Context, f func(ctx context.Context)) *Status

Go runs a goroutine safely with context support and panic recovery. It ensures the process does not crash due to an uncaught panic in the goroutine.

func GoFunc

func GoFunc(f func()) *Status

GoFunc runs a goroutine safely with panic recovery. It ensures the process does not crash due to an uncaught panic in the goroutine.

func (*Status) Wait

func (s *Status) Wait()

Wait waits for the goroutine to finish.

type ValueStatus

type ValueStatus[T any] struct {
	// contains filtered or unexported fields
}

ValueStatus provides a mechanism to wait for a goroutine that returns a value and an error.

func GoValue

func GoValue[T any](ctx context.Context, f func(ctx context.Context) (T, error)) *ValueStatus[T]

GoValue runs a goroutine safely with context support and panic recovery and returns its result and error. It ensures the process does not crash due to an uncaught panic in the goroutine.

func (*ValueStatus[T]) Wait

func (s *ValueStatus[T]) Wait() (T, error)

Wait blocks until the goroutine finishes and returns its result and error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL