event

package
v0.0.0-...-bcea9b7 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 3 Imported by: 0

README

Usage

Hooks holds a list of functions (func error) to call whenever the set is triggered.

Example

package main 

import (
	"github.com/donutloop/toolkit/event"
)

func main() {
    hooks := new(event.Hooks)
    hooks.Add(func() { 
    	// do things
    })
    hooks.Add(func() { 
        // do things 
    })
    hooks.Fire()
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hooks

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

Hooks holds a list of parameter-less functions to call whenever the set is triggered with Fire().

Example
package main

import (
	"fmt"

	"github.com/donutloop/toolkit/event"
)

func main() {
	hooks := new(event.Hooks)
	hooks.Add(func() { fmt.Println("kernel request") })

	errs := hooks.Fire()
	if len(errs) > 0 {
		for _, err := range errs {
			fmt.Printf("error: %v \n", err)
		}
	}

}
Output:

kernel request

func (*Hooks) Add

func (h *Hooks) Add(f func())

func (*Hooks) Fire

func (h *Hooks) Fire() []error

Fire calls all the functions in a given Hooks list. It launches a goroutine for each function and then waits for all of them to finish before returning.

type RecoverError

type RecoverError struct {
	Err   interface{}
	Stack []byte
}

func (*RecoverError) Error

func (e *RecoverError) Error() string

Jump to

Keyboard shortcuts

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