package bgrun
import "zgo.at/goatcounter/v2/bgrun"
Package bgrun runs jobs in the background.
This is mostly intended for "fire and forget" type of goroutines like sending an email. They typically don't really need any synchronisation as such but you do want to wait for them to finish before the program exits, or you want to wait for them in tests.
Index ¶
- func Run(name string, f func())
- func RunNoDuplicates(name string, f func())
- func Running(name string) bool
- func Wait(ctx context.Context) error
- func WaitAndLog(ctx context.Context)
- func WaitProgress(ctx context.Context) error
- func WaitProgressAndLog(ctx context.Context)
- type Job
Functions ¶
func Run ¶
func Run(name string, f func())
Run the function in a goroutine.
bgrun.Run(func() { // Do work... })
func RunNoDuplicates ¶
func RunNoDuplicates(name string, f func())
RunNoDuplicates is like Run(), but only allows one instance of this name.
It will do nothing if there's already something running with this name.
func Running ¶
Running reports if a function by this name is already running.
func Wait ¶
Wait for all goroutines to finish for a maximum of maxWait.
func WaitAndLog ¶
WaitAndLog calls Wait() and logs any errors.
func WaitProgress ¶
WaitProgress calls Wait() and prints which tasks it's waiting for.
func WaitProgressAndLog ¶
WaitProgressAndLog calls Wait(), prints which tasks it's waiting for, and logs any errors.
Types ¶
type Job ¶
func History ¶
func History() []Job
History gets the last 10,000 jobs that ran.
func List ¶
func List() []Job
List returns all running functions.
Source Files ¶
bgrun.go
- Version
- v2.2.1
- Published
- Feb 16, 2022
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 9 hours ago –
Tools for package owners.