当前位置: 首页 > 工具软件 > Chana > 使用案例 >

read data from a closed chan with has data

鲁钱明
2023-12-01
func closeChan() {
	command := make(chan bool, 5)
	command <- true
	command <- true
	command <- true
	command <- true
	close(command)
	fmt.Printf("close chan has finished\n")
	for i := 0; i < 10; i++ {
		fmt.Printf("from a closed chan:%v\n", <-command)
		/**
		close chan has finished
		from a closed chan:true
		from a closed chan:true
		from a closed chan:true
		from a closed chan:true
		from a closed chan:false
		from a closed chan:false
		from a closed chan:false
		from a closed chan:false
		from a closed chan:false
		from a closed chan:false
		*/
	}
}

Conclusion:

    After reading the existing data in chan, it will be the dafualt value

 类似资料:

相关阅读

相关文章

相关问答