Golang管道channel:管道的声明 读取 写入

为什么需要channel

Golang管道channel:管道的声明 读取 写入

channel的介绍

Golang管道channel:管道的声明 读取 写入

管道的本质是队列

  • FIFO 先进先出

Golang管道channel:管道的声明 读取 写入

定义/声明管道

Golang管道channel:管道的声明 读取 写入

channel的初始化和写数据

Golang管道channel:管道的声明 读取 写入

  • 管道的本质

Golang管道channel:管道的声明 读取 写入Golang管道channel:管道的声明 读取 写入
Golang管道channel:管道的声明 读取 写入

  • 向管道写入数据及查看管道的长度和容量

Golang管道channel:管道的声明 读取 写入Golang管道channel:管道的声明 读取 写入

  • 往管道加数据,不能超过它的容量,否则报错

Golang管道channel:管道的声明 读取 写入

Golang管道channel:管道的声明 读取 写入

从管道中读取数据

Golang管道channel:管道的声明 读取 写入Golang管道channel:管道的声明 读取 写入

  • 管道为空的情况下继续取数据会报错

Golang管道channel:管道的声明 读取 写入Golang管道channel:管道的声明 读取 写入