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.

26 lines
756 B

  1. package consensus
  2. import (
  3. "github.com/tendermint/tendermint/types"
  4. )
  5. // NOTE: if chanCap=0, this blocks on the event being consumed
  6. func subscribeToEvent(evsw types.EventSwitch, receiver, eventID string, chanCap int) chan interface{} {
  7. // listen for event
  8. ch := make(chan interface{}, chanCap)
  9. types.AddListenerForEvent(evsw, receiver, eventID, func(data types.TMEventData) {
  10. ch <- data
  11. })
  12. return ch
  13. }
  14. // NOTE: this blocks on receiving a response after the event is consumed
  15. func subscribeToEventRespond(evsw types.EventSwitch, receiver, eventID string) chan interface{} {
  16. // listen for event
  17. ch := make(chan interface{})
  18. types.AddListenerForEvent(evsw, receiver, eventID, func(data types.TMEventData) {
  19. ch <- data
  20. <-ch
  21. })
  22. return ch
  23. }