eventbus

package module
v0.0.0-...-37a6e1d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2019 License: MIT Imports: 1 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

eventbus Build Status Go Report Card GoDoc

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client publishes and subscribes to events

func NewClient

func NewClient() *Client

NewClient creates a new eventbus client

func (*Client) Close

func (c *Client) Close()

Close closes eventbus

func (*Client) Publish

func (c *Client) Publish(topic string, value interface{})

Publish publishes an event

func (*Client) Subscribe

func (c *Client) Subscribe(topic string, handler EventHandler)

Subscribe subscribes to a topic

type Event

type Event struct {
	Topic string
	Value interface{}
}

Event contains information about an event

type EventHandler

type EventHandler func(value interface{})

EventHandler an event handler

Directories

Path Synopsis
examples
1 command
2 command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址