bleep

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2021 License: MIT Imports: 4 Imported by: 1

README

Bleep

GoDoc Release Report Coverage Status

Bleep is used to peform actions on OS signals. It is highly extensible and goroutine safe. It is possible to add any number of actions and all of them are guaranteed to be performed simultaneously on the OS signals that Bleep will be listening for.

Installation

go get github.com/sinhashubham95/bleep

How to Use

The Bleep package allows you to create a new instance of the handler and also has a default handler in place that can be used directly.

Creating separate Bleep instances can be useful, when you want to perform different set of actions for different set of OS signals.

Create a New OS Signal Handler

This is used to create a new handler for performing actions on OS Signals.

import (
  "os"
  "github.com/sinhashubham95/bleep"
)

func New() {
  handler := bleep.New()
  // now this handler can be used to add or remove actions and listen to the OS signals
}
Add an Action

This is used to add an action to be executed on the OS signal listening for.

import (
  "os"
  "github.com/sinhashubham95/bleep"
)

fun Add() {
  key := bleep.Add(func (s os.Signal) {
    // do something
  })
  // this key is the unique identifier for your added action
}
Remove an Action

This is used to remove an action added to Bleep.

import (
  "github.com/sinhashubham95/bleep"
)

func Remove() {
  action := bleep.Remove("some-key")  // this key should be the same as the one returned during adding the action
  // the returned action is the one that was added using this key
}
Listen

This is used to listen for the OS signals. Note that this will wait for the signal in the go routine in which this is called.

import (
  "syscall"
  "github.com/sinhashubham95/bleep"
)

func Listen() {
  bleep.Listen(syscall.SIGINT, syscall.SIGTERM)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Actions

func Actions() map[string]Action

Actions is used to get the set of actions part of the default bleep instance

func Add

func Add(action Action) string

Add is used to add an action to the default bleep instance to be performed on an os signal

func Listen

func Listen(signals ...os.Signal)

Listen is used to listen for the provided OS signals If none are provided, then it will listen for any OS signal

func Reset

func Reset() map[string]Action

Reset is used to reset the default handler instance

Types

type Action

type Action func(os.Signal)

Action is what will be performed on an os signal

func Remove

func Remove(key string) Action

Remove is used to remove an action from the default bleep instance

type Bleep

type Bleep struct {
	// contains filtered or unexported fields
}

Bleep is the type for the handler

func New

func New() *Bleep

New is used to create a new os signal handler

func (*Bleep) Actions

func (b *Bleep) Actions() map[string]Action

Actions is used to get the set of actions part of the current bleep instance

func (*Bleep) Add

func (b *Bleep) Add(action Action) string

Add is used to add an action to be performed on an os signal

func (*Bleep) Listen

func (b *Bleep) Listen(signals ...os.Signal)

Listen is used to listen for the provided OS signals If none are provided, then it will listen for any OS signal

func (*Bleep) Remove

func (b *Bleep) Remove(key string) Action

Remove is used to remove an action added previously

func (*Bleep) Reset

func (b *Bleep) Reset() map[string]Action

Reset is used to reset the current handler instance

Jump to

Keyboard shortcuts

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