github.com/searKing/golang/go@v1.2.117/x/pool/example_test.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package pool_test 6 7 import ( 8 "context" 9 "fmt" 10 11 "github.com/searKing/golang/go/x/pool" 12 ) 13 14 func ExampleWalk() { 15 16 // chan WalkInfo 17 walkChan := make(chan any, 0) 18 19 p := pool.Walk{ 20 Burst: 1, 21 } 22 defer p.Wait() 23 24 p.Walk(context.Background(), walkChan, func(name any) error { 25 fmt.Printf("%s\n", name) 26 return nil 27 }) 28 29 for i := 0; i < 5; i++ { 30 walkChan <- fmt.Sprintf("%d", i) 31 } 32 close(walkChan) 33 // Output: 34 // 0 35 // 1 36 // 2 37 // 3 38 // 4 39 }