flare

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 2 Imported by: 1

README

Flare 🚀

A simple, lightweight signaling mechanism in Go.

Go Report Card GoDoc


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

go get github.com/twiny/flare

Usage

Basic Usage
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
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.

Bugs

Bugs or suggestions? Please visit the issue tracker.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Notifier

type Notifier interface {
	// Signal triggers the notifier, indicating an event has occurred.
	Signal()

	// Hold returns a channel that is closed when Signal is called, allowing callers to wait for a signal.
	Hold() <-chan struct{}
}

Notifier interface defines the methods for signaling and waiting on notifications.

func NewNotifier added in v0.2.0

func NewNotifier() Notifier

func NewNotifierWithCancel added in v0.2.0

func NewNotifierWithCancel(parent context.Context) (Notifier, context.CancelFunc)

Jump to

Keyboard shortcuts

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