Skip to content

Commit

Permalink
sdk/eventsdk: add GetStream() API
Browse files Browse the repository at this point in the history
it broadcasts all events on every state change.
  • Loading branch information
ilgooz committed Jun 14, 2019
1 parent 1dbcb32 commit 3d4ae83
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sdk/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
)

const (
// StreamTopic is topic used to broadcast events.
StreamTopic = "event-stream"

topic = "Event"
)

Expand Down Expand Up @@ -36,10 +39,18 @@ func (e *Event) Emit(token, eventKey string, eventData map[string]interface{}) e
return err
}

go e.ps.Pub(ev, StreamTopic)
go e.ps.Pub(ev, subTopic(s.Hash))
return nil
}

// GetStream broadcasts all events on every state change.
func (e *Event) GetStream(f *Filter) *Listener {
l := NewListener(e.ps, StreamTopic, f)
go l.Listen()
return l
}

// Listen listens events matches with eventFilter on serviceID.
func (e *Event) Listen(service string, f *Filter) (*Listener, error) {
s, err := e.db.Get(service)
Expand Down

0 comments on commit 3d4ae83

Please sign in to comment.