From ba4f3e3754402614c1b45fcfc1533a73684e906e Mon Sep 17 00:00:00 2001 From: Alexis Guerville Date: Tue, 28 Jun 2022 18:09:13 +0200 Subject: [PATCH] Fix bug in posts stream This commits fixes an issue where posts would still appear even if they had already been fetched when using the DiscardInitial option. --- reddit/stream.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/reddit/stream.go b/reddit/stream.go index 14f5b85..8c558e4 100644 --- a/reddit/stream.go +++ b/reddit/stream.go @@ -73,14 +73,17 @@ func (s *StreamService) Posts(subreddit string, opts ...StreamOpt) (<-chan *Post } ids.Add(id) + // skip this post because we are discarding initial fetch of posts if streamConfig.DiscardInitial { - streamConfig.DiscardInitial = false - break + continue } postsCh <- post } + // setting discard initial to false, since we the loop has run once already + streamConfig.DiscardInitial = false + if !infinite && n >= streamConfig.MaxRequests { break }