abortsock

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package abortsock implements abort sockets.

The abort socket is a SOCK_DGRAM Unix socket. Any datagram sent to this socket will be interpreted as a request to abort the job.

AbortSock.ListenForAbort will listen for a datagram on the abort socket. This is synchronous, so it should generally be called from a goroutine.

Example

Example for using abortsock package.

ctx := context.Background()
s, err := Open("/some/path")
if err != nil {
	log.Fatalf("Error opening abort socket: %s", err)
}
defer s.Close()
ctx = s.AttachContext(ctx)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort

func Abort(path string) error

Abort sends an abort datagram to the socket at the given path.

Types

type AbortSock

type AbortSock struct {
	// Path of socket file.
	Path string
	// Socket connection interface.
	net.PacketConn
}

AbortSock is used for receiving abort requests on a UNIX socket.

func Open

func Open(path string) (*AbortSock, error)

Open opens and returns an AbortSock. Make sure to defer Close on it.

func (*AbortSock) AttachContext

func (as *AbortSock) AttachContext(ctx context.Context) context.Context

AttachContext attaches a context to the abort socket. When an abort is received, the context is canceled.

func (*AbortSock) Close

func (as *AbortSock) Close() error

Close the abort socket.

func (*AbortSock) ListenForAbort

func (as *AbortSock) ListenForAbort(callback func())

ListenForAbort synchronously waits for an abort request. Any received datagram will be recognized as an abort request; the content of the datagram does not matter.

When an abort request is received, ListenForAbort calls the function passed to it.

If the AbortSock is closed, this function will call the callback and return immediately. To unblock a call to ListenForAbort, close the AbortSock.

Jump to

Keyboard shortcuts

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