timeout

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2017 License: MIT Imports: 8 Imported by: 47

README

timeout

Build Status Coverage Status MIT License

Timeout invocation.

Description

Run a given command with a time limit.

Disclaimer

This software is still alpha quality. We may change APIs without notice.

Synopsis

tio := &timeout.Timeout{
	Cmd:            exec.Command("perl", "-E", "say 'Hello'"),
	Duration:       10 * time.Second,
	KillAfter:      5 * time.Second,
}
exitStatus, stdout, stderr, err := tio.Run()

Author

Songmu

Documentation

Overview

Package timeout is for handling timeout invocation of external command

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	ExitCode int
	Err      error
}

Error is error of timeout

func (*Error) Error

func (err *Error) Error() string

type ExitStatus

type ExitStatus struct {
	Code int
	// contains filtered or unexported fields
}

ExitStatus stores exit information of the command

func (ExitStatus) GetChildExitCode

func (ex ExitStatus) GetChildExitCode() int

GetChildExitCode gets the exit code of the Cmd itself

func (ExitStatus) GetExitCode

func (ex ExitStatus) GetExitCode() int

GetExitCode gets the exit code for command line tools

func (ExitStatus) IsKilled

func (ex ExitStatus) IsKilled() bool

IsKilled returns the command is killed or not

func (ExitStatus) IsTimedOut

func (ex ExitStatus) IsTimedOut() bool

IsTimedOut returns the command timed out or not

type Timeout

type Timeout struct {
	Duration   time.Duration
	KillAfter  time.Duration
	Signal     os.Signal
	Foreground bool
	Cmd        *exec.Cmd
}

Timeout is main struct of timeout package

func (*Timeout) Run

func (tio *Timeout) Run() (ExitStatus, string, string, error)

Run is synchronous interface of executing command and returning information

func (*Timeout) RunCommand

func (tio *Timeout) RunCommand() (chan ExitStatus, error)

RunCommand is executing the command and handling timeout. This is primitive interface of Timeout

func (*Timeout) RunSimple

func (tio *Timeout) RunSimple(preserveStatus bool) int

RunSimple executes command and only returns integer as exit code. It is mainly for go-timeout command

Directories

Path Synopsis
cmd
go-timeout command

Jump to

Keyboard shortcuts

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