goid

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllGoids

func AllGoids() (ids []int64)

AllGoids return all goroutine's goid in the current golang process. It will try load all goid from runtime natively for better performance, and fallover to runtime.Stack, which is realy inefficient.

func GenerateTraceID added in v0.9.0

func GenerateTraceID() string

func GenerateUUID added in v0.9.5

func GenerateUUID() string

func Go

func Go(f func())

Go start an new goroutine, and copy all local storages from current goroutine.

func Goid

func Goid() (id int64)

Goid return the current goroutine's unique id. It will try get gid by native cgo/asm for better performance, and could parse gid from stack for failover supporting.

func InheritContext

func InheritContext(ic *ImmutableContext)

InheritContext load the specified ImmutableContext instance into the local storage of current goroutine.

Types

type ImmutableContext

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

ImmutableContext represents all local storages of one goroutine.

func BackupContext

func BackupContext() *ImmutableContext

BackupContext copy all local storages into an ImmutableContext instance.

type LocalStorage

type LocalStorage interface {

	// Get returns the value in the current goroutine's local storage, if it was set before.
	Get() (value any)

	// Set copy the value into the current goroutine's local storage, and return the old value.
	Set(value any) (oldValue any)

	// Del delete the value from the current goroutine's local storage, and return it.
	Del() (oldValue any)

	// Clear delete values from all goroutine's local storages.
	Clear()
}

LocalStorage provides goroutine-local variables.

func NewLocalStorage

func NewLocalStorage() LocalStorage

NewLocalStorage create and return an new LocalStorage instance.

Jump to

Keyboard shortcuts

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