You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
3.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
  1. # events
  2. `import "github.com/tendermint/tmlibs/events"`
  3. * [Overview](#pkg-overview)
  4. * [Index](#pkg-index)
  5. ## <a name="pkg-overview">Overview</a>
  6. Pub-Sub in go with event caching
  7. ## <a name="pkg-index">Index</a>
  8. * [type EventCache](#EventCache)
  9. * [func NewEventCache(evsw Fireable) *EventCache](#NewEventCache)
  10. * [func (evc *EventCache) FireEvent(event string, data EventData)](#EventCache.FireEvent)
  11. * [func (evc *EventCache) Flush()](#EventCache.Flush)
  12. * [type EventCallback](#EventCallback)
  13. * [type EventData](#EventData)
  14. * [type EventSwitch](#EventSwitch)
  15. * [func NewEventSwitch() EventSwitch](#NewEventSwitch)
  16. * [type Eventable](#Eventable)
  17. * [type Fireable](#Fireable)
  18. #### <a name="pkg-files">Package files</a>
  19. [event_cache.go](/src/github.com/tendermint/tmlibs/events/event_cache.go) [events.go](/src/github.com/tendermint/tmlibs/events/events.go) [log.go](/src/github.com/tendermint/tmlibs/events/log.go)
  20. ## <a name="EventCache">type</a> [EventCache](/src/target/event_cache.go?s=152:215#L1)
  21. ``` go
  22. type EventCache struct {
  23. // contains filtered or unexported fields
  24. }
  25. ```
  26. An EventCache buffers events for a Fireable
  27. All events are cached. Filtering happens on Flush
  28. ### <a name="NewEventCache">func</a> [NewEventCache](/src/target/event_cache.go?s=275:320#L5)
  29. ``` go
  30. func NewEventCache(evsw Fireable) *EventCache
  31. ```
  32. Create a new EventCache with an EventSwitch as backend
  33. ### <a name="EventCache.FireEvent">func</a> (\*EventCache) [FireEvent](/src/target/event_cache.go?s=534:596#L19)
  34. ``` go
  35. func (evc *EventCache) FireEvent(event string, data EventData)
  36. ```
  37. Cache an event to be fired upon finality.
  38. ### <a name="EventCache.Flush">func</a> (\*EventCache) [Flush](/src/target/event_cache.go?s=773:803#L26)
  39. ``` go
  40. func (evc *EventCache) Flush()
  41. ```
  42. Fire events by running evsw.FireEvent on all cached events. Blocks.
  43. Clears cached events
  44. ## <a name="EventCallback">type</a> [EventCallback](/src/target/events.go?s=4182:4221#L175)
  45. ``` go
  46. type EventCallback func(data EventData)
  47. ```
  48. ## <a name="EventData">type</a> [EventData](/src/target/events.go?s=236:287#L4)
  49. ``` go
  50. type EventData interface {
  51. }
  52. ```
  53. Generic event data can be typed and registered with tendermint/go-amino
  54. via concrete implementation of this interface
  55. ## <a name="EventSwitch">type</a> [EventSwitch](/src/target/events.go?s=553:760#L19)
  56. ``` go
  57. type EventSwitch interface {
  58. Service
  59. Fireable
  60. AddListenerForEvent(listenerID, event string, cb EventCallback)
  61. RemoveListenerForEvent(event string, listenerID string)
  62. RemoveListener(listenerID string)
  63. }
  64. ```
  65. ### <a name="NewEventSwitch">func</a> [NewEventSwitch](/src/target/events.go?s=902:935#L36)
  66. ``` go
  67. func NewEventSwitch() EventSwitch
  68. ```
  69. ## <a name="Eventable">type</a> [Eventable](/src/target/events.go?s=371:433#L10)
  70. ``` go
  71. type Eventable interface {
  72. SetEventSwitch(evsw EventSwitch)
  73. }
  74. ```
  75. reactors and other modules should export
  76. this interface to become eventable
  77. ## <a name="Fireable">type</a> [Fireable](/src/target/events.go?s=483:551#L15)
  78. ``` go
  79. type Fireable interface {
  80. FireEvent(event string, data EventData)
  81. }
  82. ```
  83. an event switch or cache implements fireable
  84. - - -
  85. Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)