Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Go concurrent Once

Shulou Source: shulou.com Published: 2022-06-01 10:51:47 10月03日 Update

This article mainly explains "how to use Go concurrent Once". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use Go concurrent Once.

/ / execute the specified function ffunc (o * Once) Do (ffunc ()) only once for multiple calls

The fooOnce function of the example prints only once.

Func fooOnce () {fmt.Println ("execute only once")} func main () {var once sync.Once done: = make (chan int) for I: = 0; I < 10; iTunes + {go func (index int) {once.Do (fooOnce) done

Tags: Learning content function that is ideas situations data articles more patterns knowledge knowledge points articles follow questions practice push research verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux MySQL NVidia Huawei