We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 342fa99 commit 126adf0Copy full SHA for 126adf0
go-30/obj_pool_test.go
@@ -23,6 +23,7 @@ type ObjPool struct {
23
bufChan chan *ReusableObj
24
}
25
26
+//创建一个对象池
27
func NewObjPool(numOfObj int) *ObjPool {
28
objPool := ObjPool{}
29
//创建的Buffered Channels 指定容量numOfObj
@@ -33,6 +34,7 @@ func NewObjPool(numOfObj int) *ObjPool {
33
34
return &objPool
35
36
37
+//获取对象
38
func (p *ObjPool) GetObj(timeout time.Duration) (*ReusableObj, error) {
39
select {
40
case ret := <-p.bufChan:
@@ -42,6 +44,7 @@ func (p *ObjPool) GetObj(timeout time.Duration) (*ReusableObj, error) {
42
44
43
45
46
47
+//释放对象
48
func (p *ObjPool) ReleaseObj(obj *ReusableObj) error {
49
50
case p.bufChan <- obj:
@@ -53,6 +56,7 @@ func (p *ObjPool) ReleaseObj(obj *ReusableObj) error {
53
56
54
57
55
58
func TestObjPool(t *testing.T) {
59
+ //创建一个对象池子
60
pool := NewObjPool(10)
61
for i := 0; i < 11; i++ {
62
if v, err := pool.GetObj(time.Second * 1); err != nil {
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments