spawn

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 8 Imported by: 3

README

spawn

like a salmon

spawn the current process

Build Status

as seen in:

  • server daemons
  • http servers
  • chat bots
  • long running processes of all kinds

"use anywhere!"

  • go routines
  • main function
  • "click to run the program"
  • hook it up to your signal.Notify() ?
Important notes
  • this library sets the environmental variable SPAWNED=N where N is the number of levels into this we are
  • this means if $SPAWNED is empty, we know its safe to spawn another process and exit (not an infinite loop).
  • the arguments, environment are carried over to the new process, so consider setting those before calling spawn.Spawn()
  • if your database (or something) is locked you may want to wait until after spawn check to lock the db
Usage
import "github.com/aerth/spawn"
if os.Getenv(spawn.SPAWNED) == "" {
  err := spawn.Spawn()
  if err == nil {
    os.Exit(0)
  }
}

Documentation

Overview

Package spawn a process like a salmon

Index

Constants

View Source
const (
	// SPAWNED_ENV ("$SPAWNED") is an environmental variable that is set for new processes created with Spawn()
	// Your application may use it to count spawn depth.
	// SPAWNED_ENV of 1 means first spawn, SPAWNTIME=2 means was spawned from a spawn,
	// SPAWNED_ENV=3 means this program was spawned from a spawned program that was spawned from another instance of the program.
	SPAWNED_ENV = "SPAWNED"
)

Variables

View Source
var GetEnviron func() []string = os.Environ

GetEnviron can be used, but if using Destroy() then its easier to just os.Setenv() before running Spawn() before Destroy()

Functions

func Destroy

func Destroy()

Destroy is the same as os.Exit(0) for now.

func Exe

func Exe() (self string, dir string, args []string, err error)

Exe returns information about the current running process.

func Spawn

func Spawn() error

Spawn better than a salmon!

Types

This section is empty.

Jump to

Keyboard shortcuts

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