Update comments

This commit is contained in:
Erik Johnston 2017-10-17 17:21:23 +01:00
parent 5d6169632a
commit 11251c9762
2 changed files with 5 additions and 6 deletions

View file

@ -106,9 +106,8 @@ func (n *Notifier) OnNewEvent(ev *gomatrixserverlib.Event, userID string, pos ty
} }
} }
// WaitForEvents blocks until there are events for this request after sincePos. // WaitForEvents returns a channel that produces a single stream position when
// In particular, it will return immediately if there are already events after // a new event *may* be available to return to the client.
// sincePos for the request, but otherwise blocks waiting for new events.
func (n *Notifier) WaitForEvents(req syncRequest, sincePos types.StreamPosition) <-chan types.StreamPosition { func (n *Notifier) WaitForEvents(req syncRequest, sincePos types.StreamPosition) <-chan types.StreamPosition {
// Do what synapse does: https://github.com/matrix-org/synapse/blob/v0.20.0/synapse/notifier.py#L298 // Do what synapse does: https://github.com/matrix-org/synapse/blob/v0.20.0/synapse/notifier.py#L298
// - Bucket request into a lookup map keyed off a list of joined room IDs and separately a user ID // - Bucket request into a lookup map keyed off a list of joined room IDs and separately a user ID

View file

@ -46,8 +46,8 @@ func NewUserStream(userID string, currPos types.StreamPosition) *UserStream {
} }
} }
// Wait blocks until there is a new stream position for this user, which is then returned. // Wait returns a channel that produces a single stream position when
// waitAtPos should be the position the stream thinks it should be waiting at. // a new event *may* be available to return to the client.
func (s *UserStream) Wait(ctx context.Context, waitAtPos types.StreamPosition) <-chan types.StreamPosition { func (s *UserStream) Wait(ctx context.Context, waitAtPos types.StreamPosition) <-chan types.StreamPosition {
posChannel := make(chan types.StreamPosition, 1) posChannel := make(chan types.StreamPosition, 1)
@ -79,7 +79,7 @@ func (s *UserStream) Wait(ctx context.Context, waitAtPos types.StreamPosition) <
if posChannel == ch { if posChannel == ch {
lastIdx := len(s.waitingChannels) lastIdx := len(s.waitingChannels)
s.waitingChannels[idx] = s.waitingChannels[lastIdx] s.waitingChannels[idx] = s.waitingChannels[lastIdx]
s.waitingChannels[lastIdx] = nil s.waitingChannels[lastIdx] = nil // Ensure that the channel gets GCed
s.waitingChannels = s.waitingChannels[:lastIdx] s.waitingChannels = s.waitingChannels[:lastIdx]
if len(s.waitingChannels) == 0 { if len(s.waitingChannels) == 0 {