> For the complete documentation index, see [llms.txt](https://denglj.gitbook.io/essential-go/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://denglj.gitbook.io/essential-go/02-basic-types/shu-ju-tong-dao.md).

# 数据通道

数据通道(channel)是有类型的队列，它用于协程(goroutine)之间以线程安全的的方式通信。

通道的[零值](/essential-go/02-basic-types/ling-zhi.md)是`nil`。

通道的基本用法：

{% tabs %}
{% tab title="Go" %}

```go
package main

import (
	"fmt"
)

func main() {
	// 创建一个容量为1，无缓冲的，交换int数据的channel
	ch := make(chan int)
	// 新起一个协程，将数值3通过channel传递出去
	go func() { ch <- 3 }()
	// 从channel中读取数据
	// 下面的操作会等待上面的协程发送一个值
	n := <-ch
	fmt.Printf("n: %d\n", n)
}
```

{% endtab %}

{% tab title="Output" %}

```
n: 3
```

{% endtab %}
{% endtabs %}

:point\_right: [点击此处](https://play.golang.org/p/SkDFCq6V8UA) :point\_left: 亲自在编程操场执行上述代码。
