Standard library / sync

sync.Pool.Get()

Return any available item, or call New if configured; otherwise may return nil. No particular previously stored item is guaranteed. Expected stdout: 'new\n'.

Formal Syntax & Structure

go syntaxgo
func (p *Pool) Get() any

Return Value

any

Available object, new object, or nil.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sync")
func main() { p := sync.Pool{New: func() any { return "new" }}; fmt.Println(p.Get()) }
Go Reference