Official cwtch.im peer and server implementations. https://cwtch.im
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.
 
 
 
 

32 lines
828 B

  1. package event
  2. // Queue is a wrapper around a channel for handling Events in a consistent way across subsystems.
  3. // The expectation is that each subsystem in Cwtch will manage a given an event.Queue fed from
  4. // the event.Manager.
  5. type Queue struct {
  6. EventChannel chan Event
  7. }
  8. // NewEventQueue initializes an event.Queue of the given buffer size.
  9. func NewEventQueue(buffer int) *Queue {
  10. queue := new(Queue)
  11. queue.EventChannel = make(chan Event, buffer)
  12. return queue
  13. }
  14. // Backlog returns the length of the queue backlog
  15. func (eq *Queue) Backlog() int {
  16. return len(eq.EventChannel)
  17. }
  18. // Next returns the next available event from the front of the queue
  19. func (eq *Queue) Next() (event Event) {
  20. event = <-eq.EventChannel
  21. return
  22. }
  23. // Shutdown closes our EventChannel
  24. func (eq *Queue) Shutdown() {
  25. close(eq.EventChannel)
  26. }