Skip to content

maddiesch/go-bus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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")
}