Pool

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 2 Imported by: 0

README

Pool

带类型的变量池

使用
package Pool_test

import (
	"testing"

	"github.com/Drelf2018/TypeGo/Pool"
	"github.com/Drelf2018/TypeGo/test"
)

func TestPool(t *testing.T) {
	pool := Pool.New(&test.Student{})

	s1 := pool.Get("张三")
	t.Logf("s1: %v\n", s1)

	pool.Put(s1)
	t.Logf("s1: %v\n", s1)

	s2 := pool.Get("李四")
	t.Logf("s2: %v\n", s2)

	s3 := pool.Get("王五")
	t.Logf("s3: %v\n", s3)
}
命令
go test github.com/Drelf2018/TypeGo/Pool -v
控制台
=== RUN   TestPool
    pool_test.go:14: s1: I am 张三 and my ID is 1.
    pool_test.go:17: s1: I am undefined and my ID is 0.
    pool_test.go:20: s2: I am 李四 and my ID is 0.
    pool_test.go:23: s3: I am 王五 and my ID is 1.
--- PASS: TestPool (0.00s)
PASS
ok      github.com/Drelf2018/TypeGo/Pool        0.025s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type None added in v0.1.1

type None struct{}

None is a null struct which implement Var(interface).

You can composite it in your own struct so that you don't need to implement Var.

func (*None) New added in v0.1.2

func (n *None) New()

func (*None) Reset added in v0.1.1

func (*None) Reset()

func (*None) Set added in v0.1.1

func (n *None) Set(...any)

type TypePool added in v0.1.1

type TypePool[T Var] struct {
	sync.Pool
}

func New

func New[T Var](t T) (p TypePool[T])

func (*TypePool[T]) Get added in v0.1.1

func (p *TypePool[T]) Get(args ...any) T

func (*TypePool[T]) Put added in v0.1.1

func (p *TypePool[T]) Put(ts ...T)

type Var added in v0.1.1

type Var interface {
	New()
	Set(...any)
	Reset()
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL