<commit_before># sigmon

    go get "github.com/codemodus/sigmon"

Package sigmon simplifies os.Signal handling.

## Usage

```go
type Signal
type SignalMonitor
    func New(handler func(*SignalMonitor)) (s *SignalMonitor)
    func (s *SignalMonitor) Run()
    func (s *SignalMonitor) Set(handler func(*SignalMonitor))
    func (s *SignalMonitor) Sig() Signal
    func (s *SignalMonitor) Stop()
```

### Setup

```go
import (
    "github.com/codemodus/sigmon"
)

func main() {
    sm := sigmon.New(nil)
    sm.Run()
    // Do things which cannot be affected by OS signals...

    sm.Set(signalHandler)
    // Do things which can be affected by OS signals...

    sm.Set(nil)
    // Do more things which cannot be affected by OS signals...

    sm.Stop()
    // OS signals will be handled normally.
}
```

### Signal Handler

```go
func signalHandler(sm *sigmon.SignalMonitor) {
    switch sm.Sig() {
    case sigmon.SIGHUP:
        // Reload
    case sigmon.SIGINT, sigmon.SIGTERM:
        // Stop
    case sigmon.SIGUSR1, sigmon.SIGUSR2:
        // More
    }
}
```

### Signal Handler With Context

```go
func main() {
    ctxWrap := &contextWrap{c: make(chan string), prefix: "called/wrapped - "}
    sm := sigmon.New(ctxWrap.prefixAndLowerCaseHandler)
    sm.Run()
    
    // Simulate system signal calls and print results.
    callOSSiganl(syscall.SIGINT)
    select {
    case result := <-ctxWrap.c:
        fmt.Println(result) // Output: "called/wrapped - int"
    case <-time.After(1 * time.Second):
        fmt.Println("timeout waiting for signal")
    }
    
    sm.Stop()
}
```

## More Info

N/A

## Documentation

View the [GoDoc](http://godoc.org/github.com/codemodus/sigmon)

## Benchmarks

This result is to highlight allocations.

    benchmark           iter      time/iter   bytes alloc         allocs
    ---------           ----      ---------   -----------         ------
    BenchmarkSimple   200000    10.69 μs/op     1398 B/op   28 allocs/op
<commit_msg>Update readme.<commit_after># sigmon

    go get github.com/codemodus/sigmon

Package sigmon simplifies os.Signal handling.

## Usage

```go
type Signal
type SignalMonitor
    func New(handler func(*SignalMonitor)) (s *SignalMonitor)
    func (s *SignalMonitor) Run()
    func (s *SignalMonitor) Set(handler func(*SignalMonitor))
    func (s *SignalMonitor) Sig() Signal
    func (s *SignalMonitor) Stop()
```

### Setup

```go
import (
    "github.com/codemodus/sigmon"
)

func main() {
    sm := sigmon.New(nil)
    sm.Run()
    // Do things which cannot be affected by OS signals...

    sm.Set(signalHandler)
    // Do things which can be affected by OS signals...

    sm.Set(nil)
    // Do more things which cannot be affected by OS signals...

    sm.Stop()
    // OS signals will be handled normally.
}
```

### Signal Handler

```go
func signalHandler(sm *sigmon.SignalMonitor) {
    switch sm.Sig() {
    case sigmon.SIGHUP:
        // Reload
    case sigmon.SIGINT, sigmon.SIGTERM:
        // Stop
    case sigmon.SIGUSR1, sigmon.SIGUSR2:
        // More
    }
}
```

### Signal Handler With Context

```go
func main() {
    ctxWrap := &contextWrap{c: make(chan string), prefix: "called/wrapped - "}
    
    sm := sigmon.New(ctxWrap.prefixAndLowerCaseHandler)
    sm.Run()
    
    // Simulate system signal calls and print results.
    callOSSiganl(syscall.SIGINT)
    
    select {
    case result := <-ctxWrap.c:
        fmt.Println(result) // Output: "called/wrapped - int"
    case <-time.After(1 * time.Second):
        fmt.Println("timeout waiting for signal")
    }
    
    sm.Stop()
}
```

## More Info

N/A

## Documentation

View the [GoDoc](http://godoc.org/github.com/codemodus/sigmon)

## Benchmarks

N/A

{'fraction_non_alphanumeric': 0.1392780172413793, 'fraction_numerical': 0.005926724137931034, 'mean_word_length': 2.4475394614670383, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1233214', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1199, 'n_words': 330}