Skip to content

Instantly share code, notes, and snippets.

@yumed15
Created November 22, 2023 12:17
Show Gist options
  • Save yumed15/74ad143ea927dab8b926bb473ac75dca to your computer and use it in GitHub Desktop.
Save yumed15/74ad143ea927dab8b926bb473ac75dca to your computer and use it in GitHub Desktop.
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