Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 663 Bytes

README.md

File metadata and controls

43 lines (30 loc) · 663 Bytes

Events

Lightweight generic events library for go

Installation

go get github.com/kmalaver/events

Usage

package main

import "github.com/kmalaver/events"

func main() {
  // Create new event
  e := events.New[string]()

  // Subscribe to event
  e.Subscribe(func(s string) {
    fmt.Println(s)
  })

  // Dispatch event
  e.Dispatch("Hello world!")
  
}

Event methods

Subscribe(f func(payload T)) (unsubscribe func())
Dispatch(payload T)
SubscribeOnce(f func(payload T)) (unsubscribe func())
SubscribeAsync(f func(payload T)) (unsubscribe func())
SubscribeOnceAsync(f func(payload T)) (unsubscribe func())
Wait()