添加超时功能处理
This commit is contained in:
parent
972eb004d2
commit
5dac511cae
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.nspix.com/golang/kos/util/env"
|
||||
"github.com/peterh/liner"
|
||||
"io"
|
||||
"math"
|
||||
|
@ -240,14 +241,22 @@ func (client *Client) Close() (err error) {
|
|||
}
|
||||
|
||||
func NewClient(ctx context.Context, addr string) *Client {
|
||||
var (
|
||||
err error
|
||||
timeout time.Duration
|
||||
)
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
duration := env.Get("VOX_TIMEOUT", "30s")
|
||||
if timeout, err = time.ParseDuration(duration); err != nil {
|
||||
timeout = time.Second * 30
|
||||
}
|
||||
return &Client{
|
||||
ctx: ctx,
|
||||
address: addr,
|
||||
name: filepath.Base(os.Args[0]),
|
||||
Timeout: time.Second * 30,
|
||||
Timeout: timeout,
|
||||
liner: liner.NewLiner(),
|
||||
readyChan: make(chan struct{}, 1),
|
||||
exitChan: make(chan struct{}),
|
||||
|
|
Loading…
Reference in New Issue