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.

29 lines
949 B

  1. package consensus
  2. import (
  3. "github.com/tendermint/tendermint/types"
  4. )
  5. // XXX: WARNING: these functions can halt the consensus as firing events is synchronous.
  6. // Make sure to read off the channels, and in the case of subscribeToEventRespond, to write back on it
  7. // NOTE: if chanCap=0, this blocks on the event being consumed
  8. func subscribeToEvent(evsw types.EventSwitch, receiver, eventID string, chanCap int) chan interface{} {
  9. // listen for event
  10. ch := make(chan interface{}, chanCap)
  11. types.AddListenerForEvent(evsw, receiver, eventID, func(data types.TMEventData) {
  12. ch <- data
  13. })
  14. return ch
  15. }
  16. // NOTE: this blocks on receiving a response after the event is consumed
  17. func subscribeToEventRespond(evsw types.EventSwitch, receiver, eventID string) chan interface{} {
  18. // listen for event
  19. ch := make(chan interface{})
  20. types.AddListenerForEvent(evsw, receiver, eventID, func(data types.TMEventData) {
  21. ch <- data
  22. <-ch
  23. })
  24. return ch
  25. }