forks

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2022 License: Apache-2.0 Imports: 4 Imported by: 1

README

Time-based duplicate suppression for forking processes.

Inspired by @kr.

Docs here.

Documentation

Overview

Example
package main

import (
	"log"
	"time"

	"blake.io/forks"
)

func main() {
	if forks.Child() {
		doBackgroundWorkDetached()
	} else {
		log.Fatal(forks.Maybe("", 24*time.Hour))
	}
}

func doBackgroundWorkDetached() {
	// do some work
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Child added in v0.3.0

func Child() bool

func ChildOf added in v0.5.1

func ChildOf(name string) bool

func Maybe

func Maybe(name string, d time.Duration) (forked bool, err error)

Maybe forks the current process if no other run of the binary, in the same install location, has been run in the last duration d.

If d is negative or zero, the touch file is touched and process is forked immediately.

It is an error to call Maybe from a child process forked by Maybe.

It returns an error if any.

Types

This section is empty.

Jump to

Keyboard shortcuts

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