Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 390 Bytes

README.md

File metadata and controls

31 lines (26 loc) · 390 Bytes

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()
}