https://github.com/twiny/flare
A lightweight signaling mechanism for Go.
https://github.com/twiny/flare
golang
Last synced: over 1 year ago
JSON representation
A lightweight signaling mechanism for Go.
- Host: GitHub
- URL: https://github.com/twiny/flare
- Owner: twiny
- License: mit
- Created: 2023-08-21T16:15:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-23T19:20:48.000Z (over 2 years ago)
- Last Synced: 2025-02-09T17:42:37.747Z (over 1 year ago)
- Topics: golang
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flare 🚀
A simple, lightweight signaling mechanism in Go.
[](https://goreportcard.com/report/github.com/twiny/flare)
[](https://pkg.go.dev/github.com/twiny/flare)
---
## Introduction
Flare provides an alternative to the standard context package in Go for signaling goroutines, without carrying cancellation info or other values. It's a minimalistic tool designed to provide a straightforward mechanism to signal goroutines to stop their work.
## Installation
```bash
go get github.com/twiny/flare
```
## Usage
### Basic Usage
```go
package main
import (
"github.com/twiny/flare"
)
func main() {
n := flare.NewNotifier()
// Spawn a goroutine
go func() {
select {
case <-n.Hold():
return
default:
// Do some work
}
}()
// Signal the goroutine to stop
n.Signal()
}
```
### Integration with context.Context
```go
func main() {
n, cancel := flare.NewNotifierWithCancel(context.Background())
// Canceling the context will also signal the flare Notifier.
defer cancel()
// Spawn a goroutine
go func() {
select {
case <-n.Hold():
return
default:
// Do some work
}
}()
// Signal the goroutine to stop
n.Signal()
}
```
## Wiki
More documentation can be found in the [wiki](https://github.com/twiny/flare/wiki).
## Bugs
Bugs or suggestions? Please visit the [issue tracker](https://github.com/twiny/flare/issues).