<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] > [github/go-common-poll](https://github.com/jolestar/go-commons-pool) ## 概述 Go Commons池是通用對象池 幾個重要事件: - 一個對象加入idleObjects時需要進行(鈍化)操作 - 一個對象在獲取時需要進行(激活-->校驗)操作 - 一個對象在歸還時需要進行(校驗-->鈍化)操作 - 其中任何一步失敗都需要銷毀對象 ### 配置 | Option | Default | Description | | --- | :-: | :-- | | LIFO | true | If pool is LIFO (last in, first out) | | MaxTotal | 8 | The cap of pool | | MaxIdle | 8 | Max "idle" instances in the pool | | MinIdle | 0 | Min "idle" instances in the pool | | TestOnCreate | false | Validate when object is created | | TestOnBorrow | false | Validate when object is borrowed | | TestOnReturn | false | Validate when object is returned | | TestWhileIdle | false | Validate when object is idle, see TimeBetweenEvictionRuns | | BlockWhenExhausted | true | Whether to block when the pool is exhausted | | MinEvictableIdleTime | 30m | Eviction configuration,see DefaultEvictionPolicy | | SoftMinEvictableIdleTime | math.MaxInt64 | Eviction configuration,see DefaultEvictionPolicy | | NumTestsPerEvictionRun | 3 | The maximum number of objects to examine during each run evictor goroutine | | TimeBetweenEvictionRuns | 0 | The number of milliseconds to sleep between runs of the evictor goroutine, less than 1 mean not run | ## 實例 ### Use Simple Factory <details> <summary>main.go</summary> ``` import ( "context" "fmt" "strconv" "sync/atomic" "github.com/jolestar/go-commons-pool/v2" ) func Example_simple() { type myPoolObject struct { s string } v := uint64(0) factory := pool.NewPooledObjectFactorySimple( func(context.Context) (interface{}, error) { return &myPoolObject{ s: strconv.FormatUint(atomic.AddUint64(&v, 1), 10), }, nil }) ctx := context.Background() p := pool.NewObjectPoolWithDefaultConfig(ctx, factory) obj, err := p.BorrowObject(ctx) if err != nil { panic(err) } o := obj.(*myPoolObject) fmt.Println(o.s) err = p.ReturnObject(ctx, obj) if err != nil { panic(err) } // Output: 1 } ``` </details> <br/> ### Use Custom Factory <details> <summary>main.go</summary> ``` import ( "context" "fmt" "strconv" "sync/atomic" "github.com/jolestar/go-commons-pool/v2" ) type MyPoolObject struct { s string } type MyCustomFactory struct { v uint64 } func (f *MyCustomFactory) MakeObject(ctx context.Context) (*pool.PooledObject, error) { return pool.NewPooledObject( &MyPoolObject{ s: strconv.FormatUint(atomic.AddUint64(&f.v, 1), 10), }), nil } func (f *MyCustomFactory) DestroyObject(ctx context.Context, object *pool.PooledObject) error { // do destroy return nil } func (f *MyCustomFactory) ValidateObject(ctx context.Context, object *pool.PooledObject) bool { // do validate return true } func (f *MyCustomFactory) ActivateObject(ctx context.Context, object *pool.PooledObject) error { // do activate return nil } func (f *MyCustomFactory) PassivateObject(ctx context.Context, object *pool.PooledObject) error { // do passivate return nil } func Example_customFactory() { ctx := context.Background() p := pool.NewObjectPoolWithDefaultConfig(ctx, &MyCustomFactory{}) p.Config.MaxTotal = 100 obj1, err := p.BorrowObject(ctx) if err != nil { panic(err) } o := obj1.(*MyPoolObject) fmt.Println(o.s) err = p.ReturnObject(ctx, obj1) if err != nil { panic(err) } // Output: 1 } ``` </details> <br/>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看