Skip to content

go-basic/gls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Apr 7, 2021
5b2fa8d · Apr 7, 2021

History

2 Commits
Apr 7, 2021
Apr 7, 2021
Apr 7, 2021
Apr 7, 2021
Apr 7, 2021
Apr 7, 2021
Apr 7, 2021

Repository files navigation

gls

goroutine local storage

demo

package main

import (
	"fmt"
	"github.com/go-basic/gls"
	"sync"
)

func main() {
	var wg sync.WaitGroup
	for i := 0; i < 5; i++ {
		wg.Add(1)
		go func(idx int) {
			defer wg.Done()
			defer gls.Clean()

			defer func() {
				fmt.Printf("%d: number = %d\n", idx, gls.Get("number"))
			}()
			gls.Set("number", idx+100)
		}(i)
	}
	wg.Wait()
}