亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Golang,context.TODO 會不會出錯

Golang,context.TODO 會不會出錯

Go
慕森卡 2023-03-07 13:56:47
ctx = context.TODO()cmd := exec.CommandContext(ctx, <some_cmd>, <some_arg>)fmt.Println(ctx.Err())ctx.Err() 是否會在 ctx 為 context.TODO() 時變為非零?
查看完整描述

1 回答

?
浮云間

TA貢獻1829條經驗 獲得超4個贊

context.TODO().Err() 將始終返回 nil,這在源代碼中很容易看出:

package context


// An emptyCtx is never canceled, has no values, and has no deadline.

type emptyCtx int


func (*emptyCtx) Err() error {

    return nil

}


// ...


var (

    todo       = new(emptyCtx)

)


// ...


// TODO returns a non-nil, empty Context. Code should use context.TODO when

// it's unclear which Context to use or it is not yet available (because the

// surrounding function has not yet been extended to accept a Context

// parameter).

func TODO() Context {

    return todo

}


查看完整回答
反對 回復 2023-03-07
  • 1 回答
  • 0 關注
  • 60 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號