Replace godep with dep
This commit is contained in:
parent
1e7489927c
commit
bf5616c65b
14883 changed files with 3937406 additions and 361781 deletions
73
vendor/gopkg.in/go-playground/pool.v3/examples/limited/per-unit/main.go
generated
vendored
Normal file
73
vendor/gopkg.in/go-playground/pool.v3/examples/limited/per-unit/main.go
generated
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gopkg.in/go-playground/pool.v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
p := pool.NewLimited(10)
|
||||
defer p.Close()
|
||||
|
||||
user := p.Queue(getUser(13))
|
||||
other := p.Queue(getOtherInfo(13))
|
||||
|
||||
user.Wait()
|
||||
if err := user.Error(); err != nil {
|
||||
// handle error
|
||||
}
|
||||
|
||||
// do stuff with user
|
||||
username := user.Value().(string)
|
||||
fmt.Println(username)
|
||||
|
||||
other.Wait()
|
||||
if err := other.Error(); err != nil {
|
||||
// handle error
|
||||
}
|
||||
|
||||
// do stuff with other
|
||||
otherInfo := other.Value().(string)
|
||||
fmt.Println(otherInfo)
|
||||
}
|
||||
|
||||
func getUser(id int) pool.WorkFunc {
|
||||
|
||||
return func(wu pool.WorkUnit) (interface{}, error) {
|
||||
|
||||
// simulate waiting for something, like TCP connection to be established
|
||||
// or connection from pool grabbed
|
||||
time.Sleep(time.Second * 1)
|
||||
|
||||
if wu.IsCancelled() {
|
||||
// return values not used
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ready for processing...
|
||||
|
||||
return "Joeybloggs", nil
|
||||
}
|
||||
}
|
||||
|
||||
func getOtherInfo(id int) pool.WorkFunc {
|
||||
|
||||
return func(wu pool.WorkUnit) (interface{}, error) {
|
||||
|
||||
// simulate waiting for something, like TCP connection to be established
|
||||
// or connection from pool grabbed
|
||||
time.Sleep(time.Second * 1)
|
||||
|
||||
if wu.IsCancelled() {
|
||||
// return values not used
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ready for processing...
|
||||
|
||||
return "Other Info", nil
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue