# 检查通道中是否有可用数据

如果通道中没有数据，接收操作会被阻塞。

如果您不想阻塞怎么办？

您可能会想到，可以在执行接收操作之前检查通道中是否有数据。

您不能在Go语言中这样做，因为它可能不会正确工作。在您执行完检查操作后到执行接收操作之间的时间里，别的协程可能拿走数据。

如果您想避免无限的等待，您可以使用`select`添加[超时通道](/essential-go/22-channels-and-select/timeout-reading-from-a-channel-with-select.md)或[非阻塞等待](/essential-go/22-channels-and-select/non-blocking-receive-with-select.md)。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://denglj.gitbook.io/essential-go/22-channels-and-select/checking-if-channel-has-data-available.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
