github.com/sandwich-go/boost@v1.3.29/xpool/reference_test.go (about)

     1  package xpool
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  type Event struct {
     9  	Reference
    10  
    11  	Name   string
    12  	Action string
    13  	At     time.Time
    14  }
    15  
    16  func TestName(t *testing.T) {
    17  	pool := NewReferencePool(func(r Reference) Reference {
    18  		e := &Event{Reference: r}
    19  		return e
    20  	}, func(i interface{}) {
    21  		t.Log("Reference Reset...")
    22  		e := i.(*Event)
    23  		e.Name = ""
    24  		e.Action = ""
    25  		e.At = time.Time{}
    26  	})
    27  
    28  	e := pool.Get().(*Event)
    29  	e.Decr()
    30  	e = pool.Get().(*Event)
    31  	e.Decr()
    32  	t.Log(pool.Stats())
    33  }