time

package
v1.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimerWithCancel

func TimerWithCancel(delay time.Duration) (*time.Timer, func())

TimerWithCancel exists because we had several memory leaks when using time.After in select statements. Instead, we now manually create timers, wait on them, and manually free them. See this for more details: https://www.arangodb.com/2020/09/a-story-of-a-memory-leak-in-go-how-to-properly-use-time-after/

Warning: the cancel cannot be done concurrent to reading, everything should work in the same routine

Example:

for retries := 0; true; retries++ {

	...main logic...

	timer, cancel := ftime.TimerWithCancel(utils.Backoff(retries))
	select {
	case <-ctx.Done():
		cancel()
		return ctx.Err()
	case <-timer.C:
		continue
	}
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL