idleshut

package module
v0.0.0-...-cde7779 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2018 License: BSD-3-Clause Imports: 2 Imported by: 1

Documentation

Overview

Package idleshut provides a lifecycle and idletime management tool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {

	// Start, if non-nil, is called by Process.Start. If an error is returned,
	// starting the process is aborted.
	Start func() error

	// Stop, if non-nil, is called by Process.Stop. If an error is returned,
	// stopping the process is aborted.
	Stop func() error

	// If TickDuration is non-zero, the process will count ticks where
	// the process is active or idle. Process are kept active by the user
	// calling the Process.Touch() method. When the process has been idle for
	// more than MaxIdleTicks, it will be stopped. If ticking is enabled,
	// TickError must be set or operations will result in a panic.
	TickDuration time.Duration
	TickError    func(error)

	// Tick is called by Process for every iteration of Tick. If
	// an error is returned, it is sent to TickError. Additionally,
	// IdleTick and ActiveTick are called for idle and active ticks
	// respectively.
	Tick       func() error
	IdleTick   func() error
	ActiveTick func() error

	// MaxIdleTicks, if nonzero and ticking is configured, will cause
	// the process to stop once the maximum number of ticks has been
	// reached.
	MaxIdleTicks uint
}

Config contains the options for creating a new process.

type Process

type Process struct {
	// contains filtered or unexported fields
}

Process is a lifecycle and idle process monitor.

func New

func New(cfg Config) *Process

New returns a new Process with the given configuration.

func (*Process) Running

func (p *Process) Running() bool

Running returns true if the process is currently running.

func (*Process) Start

func (p *Process) Start() error

Start initiates the process.

func (*Process) Stop

func (p *Process) Stop() error

Stop halts the process.

func (*Process) Touch

func (p *Process) Touch() bool

Touch resets the idle timer to zero.

Jump to

Keyboard shortcuts

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