Skip to content

akhmanov/gracectx-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gracectx-go

A simple utility for creating Go contexts that automatically cancel on system signals (SIGINT, SIGTERM).

Installation

go get github.com/bulatsan/gracectx-go

Usage

Basic Usage

package main

import (
	"fmt"

	"github.com/bulatsan/gracectx-go"
)

func main() {
	// Create a new context that will be canceled on SIGINT or SIGTERM
	ctx, cancel := gracectx.New()
	defer cancel()

	fmt.Println("Running... Press Ctrl+C to exit")
	<-ctx.Done() // Wait for termination signal
	fmt.Println("Shutting down gracefully")
}

Wrapping an Existing Context

ctx, cancel := gracectx.Wrap(context.Background())
defer cancel()

License

See LICENSE file for details.

About

A simple utility for creating Go contexts that automatically cancel on system signals (SIGINT, SIGTERM)

Resources

License

Stars

Watchers

Forks

Contributors

Languages