An open API service indexing awesome lists of open source software.

https://github.com/shomali11/eventbus

Eventbus
https://github.com/shomali11/eventbus

event eventbus publish subscribe

Last synced: 5 months ago
JSON representation

Eventbus

Awesome Lists containing this project

README

          

# eventbus [![Build Status](https://travis-ci.com/shomali11/eventbus.svg?branch=master)](https://travis-ci.com/shomali11/eventbus) [![Go Report Card](https://goreportcard.com/badge/github.com/shomali11/eventbus)](https://goreportcard.com/report/github.com/shomali11/eventbus) [![GoDoc](https://godoc.org/github.com/shomali11/eventbus?status.svg)](https://godoc.org/github.com/shomali11/eventbus) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

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

## Features

* Non blocking publishing of events

## Dependencies

* `maps` [github.com/shomali11/maps](https://github.com/shomali11/maps)

# Examples

## Example 1

Using `NewClient` to create an eventbus.

```go
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

```go
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
```