阅读背景:

golang context的WithTimeout实现调用自定义函数超时处理_宁静致远的博客_golang 函数超时

来源:互联网 

context的WithTimeout实现调用自定义函数超时处理


func UploadContent(content, objectName string) chan error {
	errCh := make(chan error, 1)
    return errCh
}

func  UploadFromString(content, objectName string) {
	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond * 5000))
    defer cancel()
	select {
	case <- this.UploadContent(content, objectName):
		return 
    case <- ctx.Done():
		fmt.Println(“Upload Oss Timeout"”)
        return 
	}
}


func



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: