siglistener

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package siglistener provides signal listening as a module.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

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

func New

func New(signals ...os.Signal) *Listener
Example
package main

import (
	"fmt"
	"os"
	"syscall"
	"time"

	"github.com/elisasre/go-common/service"
	"github.com/elisasre/go-common/service/module/siglistener"
)

func main() {
	// Send SIGINT after 1 second.
	go func() {
		time.Sleep(time.Second)
		syscall.Kill(syscall.Getpid(), syscall.SIGINT) //nolint: errcheck
	}()

	s := siglistener.New(os.Interrupt)
	err := service.Run(service.Modules{s})
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Service exited successfully")
}
Output:

Service exited successfully

func (*Listener) Init

func (l *Listener) Init() error

func (*Listener) Name

func (l *Listener) Name() string

func (*Listener) Run

func (l *Listener) Run() error

func (*Listener) Stop

func (l *Listener) Stop() error

Jump to

Keyboard shortcuts

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