Skip to content

shomali11/eventbus

Repository files navigation

eventbus Build Status Go Report Card GoDoc License: MIT

An event bus to facilitate publishing and subscribing to events via topics

Features

  • Non blocking publishing of events

Dependencies

Examples

Example 1

Using NewClient to create an eventbus.

package main

import "github.com/shomali11/eventbus"

func main() {
	client := eventbus.NewClient()
	defer client.Close()
}

Example 2

Using Publish and Subscribe to publish and listen to events

package main

import (
	"fmt"
	"github.com/shomali11/eventbus"
	"time"
)

func main() {
	client := eventbus.NewClient()
	defer client.Close()

	client.Publish("test", "test")

	client.Subscribe("name", func(value interface{}) {
		fmt.Println(value)
	})

	client.Subscribe("name", func(value interface{}) {
		fmt.Println(value, "is Awesome")
	})

	client.Publish("name", "Raed Shomali")

	time.Sleep(time.Second)
}

Output:

Raed Shomali
Raed Shomali is Awesome

Releases

No releases published

Packages

No packages published

Languages