Created
November 22, 2023 12:17
-
-
Save yumed15/74ad143ea927dab8b926bb473ac75dca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myPool := &sync.Pool{ | |
New: func() interface{}{ | |
fmt.Println("Creating new instance.") | |
return struct{}{} | |
} | |
} | |
myPool.Get() // no instance available, calls New; | |
instance := myPool.Get() // no instance available, calls New; | |
myPool.Put(instance) // instances in pool = 1 | |
myPool.Get() // get instance from pool | |
// Creating new instance. | |
// Creating new instance. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment