Skip to content

Commit

Permalink
Fix bug in posts stream
Browse files Browse the repository at this point in the history
This commits fixes an issue where posts would still appear
even if they had already been fetched when using the DiscardInitial
option.
  • Loading branch information
Sadzeih committed Jun 28, 2022
1 parent 63ffc3f commit ca7ec5a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions reddit/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package reddit

import (
"context"
"fmt"
"sync"
"time"
)
Expand Down Expand Up @@ -72,15 +73,19 @@ func (s *StreamService) Posts(subreddit string, opts ...StreamOpt) (<-chan *Post
break
}
ids.Add(id)
fmt.Printf("stream: id: %s\n", 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
}
Expand Down

0 comments on commit ca7ec5a

Please sign in to comment.