zl程序教程

您现在的位置是:首页 >  后端

当前栏目

2022-10-16:以下go语言代码输出什么?A:timed out;B:panic;C:没有任何输出。 package main import ( “con

Go输出语言代码 什么 2022 10 没有
2023-06-13 09:13:53 时间

2022-10-16:以下go语言代码输出什么?A:timed out;B:panic;C:没有任何输出。

package main

import (
    "context"
    "fmt"
)

func main() {
    ctx, _ := context.WithTimeout(context.Background(), 0)
    <-ctx.Done()
    fmt.Println("timed out")
}

答案选A。时间到就不会阻塞。

在这里插入图片描述