Intermediate Go (Golang)
Q47 / 100

What is sync.Once used for?

Correct! Well done.

Incorrect.

The correct answer is B) Executing a function exactly once even when called from multiple goroutines, useful for lazy initialization

B

Correct Answer

Executing a function exactly once even when called from multiple goroutines, useful for lazy initialization

Explanation

var once sync.Once; once.Do(func() { /* init */ }) runs the function at most once, safely from any number of goroutines.

Progress
47/100