github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/natives/src/sync/pool.go (about)

     1  // +build js
     2  // +build !go1.13
     3  
     4  package sync
     5  
     6  import "unsafe"
     7  
     8  type Pool struct {
     9  	local     unsafe.Pointer
    10  	localSize uintptr
    11  
    12  	store []interface{}
    13  	New   func() interface{}
    14  }
    15  
    16  func (p *Pool) Get() interface{} {
    17  	if len(p.store) == 0 {
    18  		if p.New != nil {
    19  			return p.New()
    20  		}
    21  		return nil
    22  	}
    23  	x := p.store[len(p.store)-1]
    24  	p.store = p.store[:len(p.store)-1]
    25  	return x
    26  }
    27  
    28  func (p *Pool) Put(x interface{}) {
    29  	if x == nil {
    30  		return
    31  	}
    32  	p.store = append(p.store, x)
    33  }
    34  
    35  func runtime_registerPoolCleanup(cleanup func()) {
    36  }