Skip to content

This Go package allows you to set handler functions that run when named events occur.

License

Notifications You must be signed in to change notification settings

theTardigrade/golang-events

Repository files navigation

golang-events

This Go package allows you to set handler functions that run when named events occur.

Go Reference Go Report Card

Example

package main

import (
	"fmt"
	"time"

	events "github.com/theTardigrade/golang-events"
)

func main() {
	manager := events.NewManager()

	manager.Add(events.AddOptions{
		Handler: func() {
			fmt.Println("THIS HANDLER IS CALLED WHEN EVENT ONE RUNS")
		},
		Name:               "one",
		ShouldWaitTillDone: true,
	})

	manager.Add(events.AddOptions{
		Handler: func() {
			fmt.Println("THIS HANDLER IS CALLED WHEN EVENT TWO RUNS")
		},
		Name:               "two",
		ShouldWaitTillDone: true,
	})

	manager.Add(events.AddOptions{
		Handler: func() {
			fmt.Println("THIS HANDLER IS CALLED WHEN EITHER EVENT ONE OR EVENT TWO RUNS")
		},
		Names:              []string{"one", "two"},
		ShouldWaitTillDone: true,
	})

	fmt.Println("***")
	manager.Run("one")
	fmt.Println("***")
	manager.Run("two")
	fmt.Println("***")
	manager.Run("one", "two")
	fmt.Println("***")
	manager.RunAll()
	fmt.Println("***")
}

Support

If you use this package, or find any value in it, please consider donating:

ko-fi

About

This Go package allows you to set handler functions that run when named events occur.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages