interrupt

package
v0.0.0-...-fc40e23 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0, BSD-3-Clause, MIT Imports: 2 Imported by: 7

Documentation

Overview

Package interrupt provides an interrupt helper.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Forwarder

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

Forwarder is a helper for delivering delayed signal interruptions.

This helps platform implementations with Interrupt semantics.

func (*Forwarder) Disable

func (f *Forwarder) Disable()

Disable stops interrupt forwarding. If interrupt forwarding is already disabled, Disable is a no-op.

func (*Forwarder) Enable

func (f *Forwarder) Enable(r Receiver) bool

Enable attempts to enable interrupt forwarding to r. If f has already received an interrupt, Enable does nothing and returns false. Otherwise, future calls to f.NotifyInterrupt() cause r.NotifyInterrupt() to be called, and Enable returns true.

Usage:

if !f.Enable(r) {
	// There was an interrupt.
	return
}

defer f.Disable()

Preconditions:

  • r must not be nil.
  • f must not already be forwarding interrupts to a Receiver.

func (*Forwarder) NotifyInterrupt

func (f *Forwarder) NotifyInterrupt()

NotifyInterrupt implements Receiver.NotifyInterrupt. If interrupt forwarding is enabled, the configured Receiver will be notified. Otherwise the interrupt will be delivered to the next call to Enable.

func (*Forwarder) Preempt

func (f *Forwarder) Preempt()

Preempt preempts the running context. Preempt is a weaker version of NotifyInterrupt, it doesn't set the pending flag which is set when a context isn't actually running at this moment.

type Receiver

type Receiver interface {
	// NotifyInterrupt is called when the Receiver receives an interrupt.
	NotifyInterrupt()
}

Receiver receives interrupt notifications from a Forwarder.

Jump to

Keyboard shortcuts

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