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 ¶
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 (*AbortSock) AttachContext ¶
AttachContext attaches a context to the abort socket. When an abort is received, the context is canceled.
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.