Skip to content

Files

Latest commit

bcea9b7 · May 10, 2021

History

History

bus

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Sep 30, 2017
May 10, 2021
May 10, 2021
May 10, 2021

Usage

Bus it is a simple but powerful publish-subscribe event system. It requires object to register themselves with the event bus to receive events.

Example

package main 

import (
	"github.com/donutloop/toolkit/bus"
	"log"
)

type msg struct {
	Id      int64
	counter int
}

func main() {
	b := bus.New()

    b.AddEventListener(func(m *msg) error {
        m.counter++
        return nil
    })

    b.AddEventListener(func(m *msg) error {
        m.counter++
        return nil
    })

    b.Publish(new(msg))
}