Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 520 Bytes

README.md

File metadata and controls

31 lines (24 loc) · 520 Bytes

sigtrap

simple signal traps

Quick Start

package main

import (
	"context"
	"log"
	"syscall"

	"github.com/x-mod/sigtrap"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	c := sigtrap.New(
		sigtrap.Trap(syscall.SIGINT, sigtrap.Handler(cancel)),
		sigtrap.Trap(syscall.SIGTERM, sigtrap.Handler(cancel)),
	)
	defer c.Close()
	log.Println("sigtrap: waiting ...")
	log.Println("sigtrap:", c.Serve(ctx))
}

type CTRL+C send SIGINT signal, then invoke the cancel function.