message-bus: github.com/vardius/message-bus Index | Examples | Files

package messagebus

import "github.com/vardius/message-bus"

Package messagebus provides simple async message publisher

Code:

bus := messagebus.New(runtime.NumCPU())

var wg sync.WaitGroup
wg.Add(2)

bus.Subscribe("topic", func(v bool) {
    defer wg.Done()
    fmt.Println("s1", v)
})

bus.Subscribe("topic", func(v bool) {
    defer wg.Done()
    fmt.Println("s2", v)
})

bus.Publish("topic", true)
wg.Wait()
// Unordered output:
// s1 true
// s2 true

Output:

s1 true
s2 true

Index

Examples

Package Files

bus.go doc.go

type MessageBus Uses

type MessageBus interface {
    Publish(topic string, args ...interface{})
    Subscribe(topic string, fn interface{}) error
    Unsubscribe(topic string, fn interface{}) error
}

MessageBus implements publish/subscribe messaging paradigm

func New Uses

func New(maxConcurrentCalls int) MessageBus

New creates new MessageBus maxConcurrentCalls limits concurrency by using a buffered channel semaphore

Package messagebus imports 3 packages (graph) and is imported by 2 packages. Updated 2018-09-03. Refresh now. Tools for package owners.