gls

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 2 Imported by: 0

README

Goroutine local storage

Experimental Goroutine local storage using GoRoutine address as the ID library for golang.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup()

Cleanup removes all data associated with this goroutine. If this is not called, the data may persist for the lifetime of your application. This must be called from the very first goroutine to invoke Set

func Get

func Get(key string) interface{}

Get gets the value by key as it exists for the current goroutine.

func Go

func Go(f func())

Go creates a new goroutine and runs the provided function in that new goroutine. It also associates any key,value pairs stored for the parent goroutine with the child goroutine. This function must be used if you wish to preserve the reference to any data stored in gls. This function automatically cleans up after itself. Do not call cleanup in the function passed to this function.

func Set

func Set(key string, value interface{})

Set sets the value by key and associates it with the current goroutine.

func With

func With(values Storage, f func())

With is a convenience function that stores the given values on this goroutine, calls the provided function (which will have access to the values) and then cleans up after itself.

Types

type Storage

type Storage map[string]interface{}

Storage the current goroutine local storage

func Put

func Put(timeout time.Duration) Storage

Put return a new map instance for current goroutine, it will store a global map and delete after `timeout` Duration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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