Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk/eventsdk: add GetStream() API #1054

Merged
merged 2 commits into from
Jun 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sdk/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
)

const (
topic = "Event"
// streamTopic is topic used to broadcast events.
streamTopic = "event-stream"
topic = "Event"
)

// Event exposes event APIs of MESG.
Expand Down Expand Up @@ -36,10 +38,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.
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