github.com/tursom/GoCollections@v0.3.10/util/GoroutineLocal.go (about)

     1  /*
     2   * Copyright (c) 2022 tursom. All rights reserved.
     3   * Use of this source code is governed by a GPL-3
     4   * license that can be found in the LICENSE file.
     5   */
     6  
     7  package util
     8  
     9  import (
    10  	"sync"
    11  
    12  	"github.com/tursom/GoCollections/lang"
    13  )
    14  
    15  var (
    16  	goroutineLocalMap = sync.Map{}
    17  )
    18  
    19  type (
    20  	// GoroutineLocal goroutine local variable
    21  	GoroutineLocal[T any] struct {
    22  		lang.BaseObject
    23  	}
    24  )
    25  
    26  func WithGoroutineLocal(f func()) {
    27  	initGoroutineLocal()
    28  	defer freeGoroutineLocal()
    29  
    30  	f()
    31  }
    32  
    33  func (g *GoroutineLocal[T]) Get() T {
    34  	//TODO implement me
    35  	panic("implement me")
    36  }
    37  
    38  func (g *GoroutineLocal[T]) Put(value T) {
    39  	//TODO implement me
    40  	panic("implement me")
    41  }
    42  
    43  func (g *GoroutineLocal[T]) Remove() {
    44  	//TODO implement me
    45  	panic("implement me")
    46  }
    47  
    48  func initGoroutineLocal() {
    49  	//TODO implement me
    50  	goroutineLocalMap.Store(lang.GoId(), nil)
    51  	panic("implement me")
    52  }
    53  
    54  func freeGoroutineLocal() {
    55  	goroutineLocalMap.Delete(lang.GoId())
    56  }