bgrun

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: EUPL-1.2, ISC, MIT, + 1 more Imports: 11 Imported by: 0

Documentation

Overview

Package bgrun allows simple synchronisation of goroutines.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(name string) func()

Add a new function to the waitgroup and return the done.

done := bgrun.Add()
go func() {
   defer done()
   defer zlog.Recover()
}()

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

func Running(name string) bool

Running reports if a function by this name is already running.

func Wait

func Wait() error

Wait for all goroutines to finish for a maximum of maxWait.

func WaitAndLog

func WaitAndLog()

WaitAndLog calls Wait() and logs any errors.

func WaitProgress

func WaitProgress() error

WaitProgress calls Wait() and prints which tasks it's waiting for.

func WaitProgressAndLog

func WaitProgressAndLog()

WaitProgressAndLog calls Wait(), prints which tasks it's waiting for, and logs any errors.

Types

This section is empty.

Jump to

Keyboard shortcuts

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