signals

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Example (WithUnregisteredSignals)
dctx, cancel := context.WithTimeout(context.TODO(), time.Millisecond*100)
defer cancel()

ctx := WithSignals(dctx, syscall.SIGUSR1)
go func() {
	time.Sleep(10 * time.Millisecond) // after some time SIGUSR2 is sent
	// mimicking a signal from the outside, WithSignals will not handle it
	syscall.Kill(syscall.Getpid(), syscall.SIGUSR2)
}()

<-ctx.Done()
fmt.Println("finished")
Output:

finished

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithSignals

func WithSignals(ctx context.Context, sigs ...os.Signal) context.Context

WithSignals returns a context that is canceled with any signal in sigs.

Example
ctx := WithSignals(context.Background(), syscall.SIGUSR1)
go func() {
	time.Sleep(500 * time.Millisecond) // after some time SIGUSR1 is sent
	// mimicking a signal from the outside
	syscall.Kill(syscall.Getpid(), syscall.SIGUSR1)
}()

<-ctx.Done()
fmt.Println("finished")
Output:

finished

func WithStandardSignals

func WithStandardSignals(ctx context.Context) context.Context

WithStandardSignals cancels the context on os.Interrupt, syscall.SIGTERM.

Types

This section is empty.

Jump to

Keyboard shortcuts

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