@@ -13,24 +13,24 @@ import (
1313)
1414
1515var (
16- errPoolIsFull = errors .New ("_examples: pool is full " )
17- errPoolIsClosed = errors .New ("_examples: pool is closed" )
16+ errPoolExhausted = errors .New ("_examples: pool is exhausted " )
17+ errPoolClosed = errors .New ("_examples: pool is closed" )
1818)
1919
20- func acquire () (int , error ) {
20+ func acquire (ctx context. Context ) (int , error ) {
2121 return 0 , nil
2222}
2323
24- func release (resource int ) error {
24+ func release (ctx context. Context , resource int ) error {
2525 return nil
2626}
2727
28- func newPoolFullErr (ctx context.Context ) error {
29- return errPoolIsFull
28+ func newPoolExhaustedErr (ctx context.Context ) error {
29+ return errPoolExhausted
3030}
3131
3232func newPoolClosedErr (ctx context.Context ) error {
33- return errPoolIsClosed
33+ return errPoolClosed
3434}
3535
3636func main () {
@@ -42,36 +42,36 @@ func main() {
4242 resource , err := pool .Take (ctx )
4343 fmt .Println (resource , err )
4444
45- // However, the pool is full after taking one resource without putting.
46- // It will return a full error.
45+ // However, the pool is exhausted after taking one resource without putting.
46+ // It will return an exhausted error.
4747 resource , err = pool .Take (ctx )
48- fmt .Println (resource , err , err == rego .ErrPoolIsFull )
48+ fmt .Println (resource , err , err == rego .ErrPoolExhausted )
4949
5050 // Put the resource back to the pool.
51- pool .Put (resource )
52- pool .Close ()
51+ pool .Put (ctx , resource )
52+ pool .Close (ctx )
5353
5454 // Now, the pool is closed so any taking from the pool will return a closed error.
5555 resource , err = pool .Take (ctx )
56- fmt .Println (resource , err , err == rego .ErrPoolIsClosed )
56+ fmt .Println (resource , err , err == rego .ErrPoolClosed )
5757
5858 // Create a pool with limit and fast-failed and new error funcs.
59- pool = rego .New (1 , acquire , release , rego .WithFastFailed (), rego .WithPoolFullErr ( newPoolFullErr ), rego .WithPoolClosedErr (newPoolClosedErr ))
59+ pool = rego .New (1 , acquire , release , rego .WithFastFailed (), rego .WithPoolExhaustedErr ( newPoolExhaustedErr ), rego .WithPoolClosedErr (newPoolClosedErr ))
6060
6161 // Take one resource from pool which is ok.
6262 resource , err = pool .Take (ctx )
6363 fmt .Println (resource , err )
6464
65- // However, the pool is full after taking one resource without putting.
66- // It will return a customizing full error.
65+ // However, the pool is exhausted after taking one resource without putting.
66+ // It will return a customizing exhausted error.
6767 resource , err = pool .Take (ctx )
68- fmt .Println (resource , err , err == errPoolIsFull )
68+ fmt .Println (resource , err , err == errPoolExhausted )
6969
7070 // Put the resource back to the pool.
71- pool .Put (resource )
72- pool .Close ()
71+ pool .Put (ctx , resource )
72+ pool .Close (ctx )
7373
7474 // Now, the pool is closed so any taking from the pool will return a customizing closed error.
7575 resource , err = pool .Take (ctx )
76- fmt .Println (resource , err , err == errPoolIsClosed )
76+ fmt .Println (resource , err , err == errPoolClosed )
7777}
0 commit comments