event

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 1 Imported by: 0

README

The github.com/lltpkg/event package provides a simple and thread-safe mechanism for managing events and listeners in Go applications.

Installation

To use the event package in your Go project, you can use the following go get command:

go get -u github.com/lltpkg/event

Quick start

package main

import (
	"fmt"

	"github.com/lltpkg/event"
)

func main() {
	evName := "Greeting"
	go func() {
		data := "World"
		event.FireEvent(evName, data)
	}()
	evChan, unSub := event.EventChannel(evName)
	defer unSub()
	receivedData := <-evChan
	fmt.Println("Hello,", receivedData)
}

Usage

Creating Events and Listeners

The package allows you to create named events and associate listeners with them. Use the EventChannel function to create an event channel and associate a cleanup function with it:

// Create an event channel(listener) for "exampleEvent"
eventChan, cleanup := event.EventChannel("exampleEvent")
// Cleanup resources when done
defer cleanup()


Triggering Events

You can trigger events using the FireEvent function. This function allows you to send data to all registered listeners for a specific event:

// Trigger the event anywhere else
event.FireEvent("exampleEvent", "event data")

Contribution

Feel free to open issues and submit pull requests for improvements or bug fixes. We appreciate any contributions that make the event package more robust and versatile.

Maintainers

Kai - Ly Luong Thien - Maintainer of github.com/lltpkg/event 1. Kai - @lyluongthien

License

This package is licensed under the MIT License.

Note: Update the documentation based on the actual functionality and features provided by the event package. Include details about how to use the package, any configuration options, and examples for common use cases.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventChannel added in v0.0.2

func EventChannel(evName string) (eventChannel chan interface{}, unsubscribe func())

func FireEvent

func FireEvent(evName string, data interface{})

Types

This section is empty.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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