1 Star 0 Fork 0

c01dface/s-go-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
channels.go 721 Bytes
一键复制 编辑 原始数据 按行查看 历史
c01dface 提交于 2024-12-03 15:29 . add channels.go
package main
// Channels are the pipes that connect concurrent goroutines.
// You can send values into channels from one goroutine and receive
// those values into another goroutine.
// By default sends and receives block until both the sender and receiver are ready.
import "fmt"
func main() {
// create a new channel with make(chan val-type)
// Channels are typed by the values they convey.
messages := make(chan string)
// send a value into a channel using the channel <- syntax.
// Here we send "ping" to the messages channel we made above, from
// a new goroutine.
go func() {
messages <- "ping"
}()
// The <- channel syntax receives a value from the channel.
msg := <-messages
fmt.Println(msg)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vmalloc/s-go-example.git
git@gitee.com:vmalloc/s-go-example.git
vmalloc
s-go-example
s-go-example
master

搜索帮助