ossignal

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ossignal provides a Task that listens for signals from the operating system. Signal capture begins at NewTask construction time.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSignals

func DefaultSignals() []os.Signal

DefaultSignals returns the os signals that will cause this task to exit.

Types

type Option

type Option func(options *options)

Option is an option func for NewTask.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger to be used.

func WithOnSignal

func WithOnSignal(fn func(os.Signal)) Option

WithOnSignal sets a callback that is invoked after the signal is logged.

func WithSignalLogLevel

func WithSignalLogLevel(level slog.Level) Option

WithSignalLogLevel sets the log level used when an OS signal is received.

func WithSignals

func WithSignals(signals ...os.Signal) Option

WithSignals overrides the default signals being listened for.

type Task

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

Task is a task.Task that waits for a termination signal from the OS.

func NewTask

func NewTask(opts ...Option) *Task

NewTask creates a new Task. Signal capture begins immediately upon construction. Panics if the resolved signals list is empty.

Example

ExampleNewTask demonstrates creating an ossignal Task that listens for the default termination signals (SIGINT, SIGTERM, SIGQUIT).

package main

import (
	"log/slog"

	"github.com/wood-jp/task/ossignal"
)

func main() {
	t := ossignal.NewTask(
		ossignal.WithLogger(slog.Default()),
	)
	_ = t
}

func (*Task) Name

func (t *Task) Name() string

Name returns the name of this task, including the signals being listened for.

func (*Task) Run

func (t *Task) Run(ctx context.Context) error

Run blocks until an OS signal is received or the context is cancelled, then returns nil. Returns ErrAlreadyStarted if called more than once.

Jump to

Keyboard shortcuts

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