Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 1.12 KB

README.md

File metadata and controls

50 lines (37 loc) · 1.12 KB

go-bus - Generic Event Bus

current Codecov Doc Build Status License

A multi-producer multi-consumer generic event bus.

🔨 Usage

Get

go get github.com/maddiesch/go-bus

Import

import (
  "github.com/maddiesch/go-bus"
)

Use

func main() {
  eventBus := bus.New[string]()

  subscription, cancel := eventBus.Sink()
  defer cancel()

  go produceEvents(eventBus)

  for event := range subscription {
    switch event {
    case "stop":
      return
    default:
      fmt.Println(event)
    }
  }
}

func produceEvents(eventBus *bus.Bus[string]) {
  eventBus.Publish("Hello, World!")
  eventBus.Publish("stop")
}