Documentation
¶
Overview ¶
Package malib provides functions supporting mains package.
Index ¶
- func CheckForPanic(err error) (panicString string)
- func KeystrokesThread(silent bool, errorSink parl.ErrorSink1, stdin parl.ClosableSink[string])
- func ProcessStart(pid int) (processStart time.Time, err error)
- func ProcessStartTime() (createTime time.Time)
- func SystemUpSince() (upSince time.Time, err error)
- type ErrStore
- type StdinReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckForPanic ¶
CheckForPanic returns a non-empty string when err contains a panic
- the string contains code location for the panic and the recovery
func KeystrokesThread ¶
func KeystrokesThread(silent bool, errorSink parl.ErrorSink1, stdin parl.ClosableSink[string])
keystrokesThread reads blocking from os.Stdin therefore cannot be canceled
- silent true: nothing is printed on os.Stdin closing
- silent false: “mains.keystrokesThread standard input closed” may be printed to standard error on os.Stdin closing
- errorSink present: receives any errors returned by or panic in os.Stdin.Read
- errorSink nil: errors are printed to standard error
- stdin receives text lines from standard input with line terminator removed
- on os.Stdin closing, keystrokesThread closes the stdin line-input channel
- — the close may be deferred until a key is pressed or the process exits -
- Because os.Stdin cannot be closed and os.Stdin.Read is blocking:
- — the thread may blockindfinitiely until process exit
- — therefore, keystrokesThread is a top-level function not waited upon
- — purpose is to minimize objects kept in memory until the thread exits
- on [Keystrokes.CloseNow], keystrokesThread exits on the following keypress
- StdinReader converts any error to io.EOF
- parl.Infallible prints any errors to standard error, should not be any
- —
- -verbose=mains.keystrokesThread
func ProcessStart ¶
ProcessStart returns start time for process pid with second resolution
func ProcessStartTime ¶
ProcessStartTime returns start time for process pid with second resolution
- panic on troubles
func SystemUpSince ¶
SystemUpSince returns boot time second resolution
Types ¶
type ErrStore ¶
ErrStore is a slice to distinguish multiple invocations of AddErr
- must be initialization free
- must be thread-safe
type StdinReader ¶
type StdinReader struct {
// contains filtered or unexported fields
}
StdinReader is a reader wrapping the unclosable os.Stdin.Read
func NewStdinReader ¶
func NewStdinReader(errorSink parl.ErrorSink1, isError ...*atomic.Bool) (stdinReader *StdinReader)
NewStdinReader returns a error-free reader of standard input that closes on error
- errorSink pressent: receives any errors returned by os.Stdin.Read or runtime panic in this method.
- errorSink nil: errors are printed to standard error
- isError: optional atomic set to true on first error or standard input closing -
- StdinReader.Read returns bytes read from os.Stdin standard input until close or error
- os.Stdin.Read is blocking and os.Stdin cannot be closed
- Therefore, the thread invoking Read may remain until the process exits
- StdinReader removes all inband errors and panics and only propagates the fact that no more bytes are available via EOF error
func (*StdinReader) Read ¶
func (r *StdinReader) Read(p []byte) (n int, err error)
Read reads from standard input
- p buffer, max length to read
- n: the number of bytes read
- err: Read never returns any other error than io.EOF on error, panic or close
- — subsequent invocations after first EOF receives EOF -
- errors and runtime panics are sent to the errorSink or printed to stderr
- os.Stdin cannot be closed so a blocking StdinReader.Read cannot be canceled
- the thread invoking Read may remain blocked until process exit
- if the stdin pipe is closed by another process, Read keeps blocking but returns on the next keypress. Then, an error os.ErrClosed is sent to errorSink and io.EOF is returned
- on process exit, Read is unblocked as stdin is closed
Click to show internal directories.
Click to hide internal directories.