File: pool_above_1_24.go

package info (click to toggle)
golang-github-olekukonko-errors 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 500 kB
  • sloc: makefile: 2
file content (24 lines) | stat: -rw-r--r-- 716 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//go:build go1.24
// +build go1.24

package errors

import "runtime"

// setupCleanup configures a cleanup function for an *Error to auto-return it to the pool.
// Only active for Go 1.24+; uses runtime.AddCleanup when autoFree is set and pooling is enabled.
func (ep *ErrorPool) setupCleanup(e *Error) {
	if currentConfig.autoFree {
		runtime.AddCleanup(e, func(_ *struct{}) {
			if !currentConfig.disablePooling {
				ep.Put(e) // Return to pool when cleaned up
			}
		}, nil) // No additional context needed
	}
}

// clearCleanup is a no-op for Go 1.24 and above.
// Cleanup is managed by runtime.AddCleanup; no explicit removal is required.
func (ep *ErrorPool) clearCleanup(e *Error) {
	// No-op for Go 1.24+
}