v.io: v.io/x/ref/lib/signals Index | Files

package signals

import "v.io/x/ref/lib/signals"

Package signals implements utilities for managing process shutdown with support for signal-handling.

Index

Package Files

signals.go

Constants

const (
    DoubleStopExitCode = 1
)

Variables

var SameSignalTimeWindow time.Duration

SameSignalTimeWindow specifies the time window during which multiple deliveries of the same signal are counted as one signal. If set to zero, no such de-duping occurs. This is useful in situations where a process receives a signal explicitly sent by its parent when the parent receives the signal, but also receives it independently by virtue of being part of the same process group.

This is a variable, so that it can be set appropriately. Note, there is no locking around it, the assumption being that it's set during initialization and never reset afterwards.

func Default Uses

func Default() []os.Signal

Default returns a set of platform-specific signals that applications are encouraged to listen on.

func ShutdownOnSignals Uses

func ShutdownOnSignals(ctx *context.T, signals ...os.Signal) <-chan os.Signal

ShutdownOnSignals registers signal handlers for the specified signals, or, if none are specified, the default signals. The first signal received will be made available on the returned channel; upon receiving a second signal, the process will exit if that signal differs from the first, or if the same it arrives more than a second after the first.

type ContextDoneSignal Uses

type ContextDoneSignal string

func (ContextDoneSignal) Signal Uses

func (ContextDoneSignal) Signal()

func (ContextDoneSignal) String Uses

func (s ContextDoneSignal) String() string

type Handler Uses

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

Handler represents a signal handler that can be used to wait for signal reception or context cancelation as per NotifyWithCancel. In addition it can be used to register additional cancel functions to be invoked on signal reception or context cancelation.

func ShutdownOnSignalsWithCancel Uses

func ShutdownOnSignalsWithCancel(ctx *context.T, signals ...os.Signal) (*context.T, *Handler)

ShutdownOnSignalsWithCancel is like ShutdownOnSignals except it forks the supplied context to obtain a cancel function which is called by the returned function when a signal is received. The returned function can be called to wait for the signal to be received or for the context to be canceled. Typical usage would be:

   func main() {
	    ctx, shutdown := v23.Init()
     defer shutdown()
     ctx, handler := ShutdownOnSignalsWithCancel(ctx)
     defer handler.WaitForSignal()

     _, srv, err := v23.WithNewServer(ctx, ...)

   }

waitForInterrupt will wait for a signal to be received at which point it will cancel the context and thus the server created by WithNewServer to initiate its internal shutdown. The deferred shutdown returned by v23.Init() will then wait for that the server to complete its shutdown. Canceling the context is treated as receipt of a custom signal, ContextDoneSignal, in terms of its returns value.

func (*Handler) RegisterCancel Uses

func (h *Handler) RegisterCancel(fns ...func())

RegisterCancel registers one or more cancel functions to be invoked when a signal is received or the original context is canceled.

func (*Handler) WaitForSignal Uses

func (h *Handler) WaitForSignal() os.Signal

WaitForSignal will wait for a signal to be received. Context cancelation is translated into a ContextDoneSignal signal.

Package signals imports 6 packages (graph) and is imported by 98 packages. Updated 2020-10-16. Refresh now. Tools for package owners.