There's a New function inside a Pool struct in the source code of the sync
package that's defined like this
type Pool struct {
local unsafe.Pointer // local fixed-size per-P pool, actual type is [P]poolLocal
localSize uintptr // size of the local array
// New optionally specifies a function to generate
// a value when Get would otherwise return nil.
// It may not be changed concurrently with calls to Get.
New func() interface{}
}
At line 103 of a golang stack trace package created by Facebook, there's an anonymous function defined inside a sync pool struct like this with the New:
label:
var pcsPool = sync.Pool{
New: func() interface{} {
return make([]uintptr, maxStackSize)
},
}
So, going from the comments in the source code, I'm assuming that the Facebook package has "specified a function to generate a value when Get would otherwise return nil," but why might it be defined with New:
like this?