In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to set the Go channel buffer." Xiao Bian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to set the Go channel buffer" can help you solve the problem.
channel buffer
The channel can set the buffer, and the buffer size is specified by the second parameter of make:
ch := make(chan int, 100)
Buffered channels allow data transmission at the sender and data acquisition at the receiver to be asynchronous, that is, the data sent by the sender can be placed in the buffer and can wait for the receiver to acquire the data, rather than requiring the receiver to acquire the data immediately.
However, since the size of the buffer is limited, there must be a receiver to receive data, otherwise the buffer will be full and the data sender will not be able to send data.
Note: If the channel is unbuffered, the sender blocks until the receiver receives a value from the channel. If the channel is buffered, the sender blocks until the value sent is copied into the buffer; if the buffer is full, it means waiting until a receiver gets a value. The receiver blocks until it has a value to receive.
examples
package main
import "fmt"
func main() {
//Here we define a buffered channel that can store integer types
//buffer size is 2
ch := make(chan int, 2)
//since ch is a buffered channel, we can send two data at the same time
//instead of having to synchronize the read data immediately
ch
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.