goemits

package module
v0.0.5-0...-938113e Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: MIT Imports: 5 Imported by: 0

README

goemits

Documentation Go Report Card Build Status Coverage Status

Event emitters based on pubsub in Redis.

package main

import (
	"fmt"

	"github.com/saromanov/goemits"
)

func main() {
	emit := goemits.New(goemits.Config{
		RedisAddress: "127.0.0.1:6379",
	})
	emit.On("connect", func(message interface{}) {
		fmt.Println("Found: ", message)
		emit.Emit("disconnect", "data")
	})

	emit.On("disconnect", func(message interface{}) {
		fmt.Println("Disconnect")
		emit.Quit()
	})
	

	emit.OnAny(func(message interface{}) {
		//This get any events
	})
	emit.Start()
}

Emit of the event

emit.On("disconnect", "now")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// RedisAddress defines address for connect to Redis
	RedisAddress string
	// Number of maximum listeners
	MaxListeners int
}

Config defines attributes for start

type Goemits

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

Goemits defines main structure of the app

func New

func New(c Config) *Goemits

New provides initialization of Goemits This should call in the first place

func (*Goemits) Emit

func (ge *Goemits) Emit(event string, message interface{}) error

Emit event

func (*Goemits) EmitAll

func (ge *Goemits) EmitAll(message interface{})

EmitAll provides fire message to all of listeners

func (*Goemits) EmitMany

func (ge *Goemits) EmitMany(events []string, message interface{})

EmitMany provides fire message to list of listeners

func (*Goemits) On

func (ge *Goemits) On(event string, f func(interface{}))

On provides subscribe to event

func (*Goemits) OnAny

func (ge *Goemits) OnAny(f func(interface{}))

OnAny provides catching any event

func (*Goemits) Ping

func (ge *Goemits) Ping() error

Ping provides checking of redis connection and Goemits

func (*Goemits) Quit

func (ge *Goemits) Quit() error

Quit provides break up main loop

func (*Goemits) RemoveListener

func (ge *Goemits) RemoveListener(listener string)

RemoveListener from store and unsubscribe from "listener" channel

func (*Goemits) RemoveListeners

func (ge *Goemits) RemoveListeners(listeners []string)

RemoveListeners from the base

func (*Goemits) SetMaxListeners

func (ge *Goemits) SetMaxListeners(num int)

SetMaxListeners provides limitiation of amount of listeners

func (*Goemits) Start

func (ge *Goemits) Start()

Start provides beginning of catching messages

Jump to

Keyboard shortcuts

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