Skip to content

Commit 1c45db7

Browse files
authored
Updated the README.md for the ListingStream and have a working example (#229)
* Updated ListingStream example. * Added example with ListingStream
1 parent 0cff99f commit 1c45db7

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

README.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,39 @@ await reddit.RSlashAll.New.Take(2).ForEachAsync(page => {
105105

106106
**Using ListingStreams**
107107

108-
Use ListingStreams to infinitely yeild new Things posted to reddit
108+
Use `ListingStreams` to infinitely yield new `Things` posted to reddit
109109

110110
Example:
111111

112112
```csharp
113-
// get all new comments as they are posted.
114-
var comments = subreddit.Comments.GetListingStream();
113+
// Create the stream
114+
ListingStream<Post> postStream = subreddit.GetPosts(Subreddit.Sort.New).Stream();
115+
// Note: Don't set the max in the GetPosts() method, otherwise the stream will
116+
// stop working as soon as you reach this value.
117+
// The handling method that will be call on each new post
118+
postStream.Subscribe(post => logger.LogDebug($"Post : [{post.Title} at {post.CreatedUTC}]"));
119+
// Start listening
120+
await postStream.Enumerate(cancellationToken);
121+
```
115122

116-
await comments.Execute();
117-
foreach (var comment in subreddit.CommentStream)
118-
{
119-
Console.WriteLine(DateTime.Now + " New Comment posted to /r/example: " + comment.ShortLink);
120-
}
123+
```csharp
124+
// Any properties that returns a Listing<T> has its stream version, another example, new modmail.
125+
ListingStream<PrivateMessage> modMailStream = reddit.User.GetModMail().Stream();
126+
modMailStream.Subscribe(message => logger.LogDebug($"ModMail : {message.Subject}"));
127+
await modMailStream.Enumerate(cancellationToken);
121128
```
122129

123130
```csharp
124-
// get new modmail
125-
var newModmail = user.ModMail.GetListingStream();
126-
foreach (var message in newModmail)
127-
{
128-
if (message.FirstMessageName == "")
129-
message.Reply("Thanks for the message - we will get back to you soon.");
130-
}
131+
// Need more than one stream at a time ?
132+
ListingStream<Post> postStream = subreddit.GetPosts(Subreddit.Sort.New).Stream();
133+
postStream.Subscribe(post => logger.LogDebug($"Post : [{post.Title} at {post.CreatedUTC}]"));
134+
ListingStream<PrivateMessage> modMailStream = reddit.User.GetModMail().Stream();
135+
modMailStream.Subscribe(message => logger.LogDebug($"ModMail : {message.Subject}"));
136+
137+
await Task.WhenAll({
138+
postStream.Enumerate(cancellationToken),
139+
modMailStream.Enumerate(cancellationToken)
140+
});
131141
```
132142

133143
## Development

0 commit comments

Comments
 (0)