larsp / bus

Simple worker based publish/subscribe style communication between Go components.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bus

Build Status GoDoc

Simple worker based publish/subscribe style communication between Go components.

Example:

package main

import (
	"fmt"
	"sync"

	. "github.com/larsp/bus"
)

type SomeEvent struct {
	Message string
	WG      *sync.WaitGroup
}

func SomeEventHandler(event SomeEvent) {
	fmt.Println(event.Message)
	event.WG.Done()
}

func main() {
	bus := New(10, 2) // channel can buffer 10 events and 2 workers consume from that channel
	var wg sync.WaitGroup
	wg.Add(1)

	bus.Register(SomeEventHandler)
	bus.Publish(SomeEvent{"Hallo!", &wg})
	wg.Wait() // Waiting for the handler to process the event
}

For documentation, check godoc.

About

Simple worker based publish/subscribe style communication between Go components.

License:Apache License 2.0


Languages

Language:Go 100.0%