tendermint/events
Anton Kaliaev 4123d54bf6
change service#Start to return just error (Refs #45)
```
@melekes
yeah, bool is superfluous
@ethanfrey
If I remember correctly when I was writing test code, if I call Start() on a Service that is already running, it returns (false, nil). Only if I try to legitimately start it, but it fails in startup do I get an error.
The distinction is quite important to make it safe for reentrant calls. The other approach would be to have a special error type like ErrAlreadyStarted, then check for that in your code explicitly. Kind of like if I make a db call in gorm, and get an error, I check if it is a RecordNotFound error, or whether there was a real error with the db query.
@melekes
Ah, I see. Thanks. I must say I like ErrAlreadyStarted approach more (not just in Golang)
```
2017-11-06 12:18:04 -05:00
..
Makefile docs: go-events -> tmlibs/events 2017-04-21 16:25:23 -04:00
README.md docs: go-events -> tmlibs/events 2017-04-21 16:25:23 -04:00
event_cache.go fix zeroed buffer getting flushed to the empty event 2017-10-23 18:52:31 +01:00
event_cache_test.go fix zeroed buffer getting flushed to the empty event 2017-10-23 18:52:31 +01:00
events.go Logger interface and tmLogger impl based on go-kit 2017-05-05 21:43:07 +04:00
events_test.go change service#Start to return just error (Refs #45) 2017-11-06 12:18:04 -05:00

README.md

events

import "github.com/tendermint/tmlibs/events"

Overview

Pub-Sub in go with event caching

Index

Package files

event_cache.go events.go log.go

type EventCache

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

An EventCache buffers events for a Fireable All events are cached. Filtering happens on Flush

func NewEventCache

func NewEventCache(evsw Fireable) *EventCache

Create a new EventCache with an EventSwitch as backend

func (*EventCache) FireEvent

func (evc *EventCache) FireEvent(event string, data EventData)

Cache an event to be fired upon finality.

func (*EventCache) Flush

func (evc *EventCache) Flush()

Fire events by running evsw.FireEvent on all cached events. Blocks. Clears cached events

type EventCallback

type EventCallback func(data EventData)

type EventData

type EventData interface {
}

Generic event data can be typed and registered with tendermint/go-wire via concrete implementation of this interface

type EventSwitch

type EventSwitch interface {
    Service
    Fireable

    AddListenerForEvent(listenerID, event string, cb EventCallback)
    RemoveListenerForEvent(event string, listenerID string)
    RemoveListener(listenerID string)
}

func NewEventSwitch

func NewEventSwitch() EventSwitch

type Eventable

type Eventable interface {
    SetEventSwitch(evsw EventSwitch)
}

reactors and other modules should export this interface to become eventable

type Fireable

type Fireable interface {
    FireEvent(event string, data EventData)
}

an event switch or cache implements fireable


Generated by godoc2md