@@ -105,29 +105,39 @@ await reddit.RSlashAll.New.Take(2).ForEachAsync(page => {
105
105
106
106
** Using ListingStreams**
107
107
108
- Use ListingStreams to infinitely yeild new Things posted to reddit
108
+ Use ` ListingStreams ` to infinitely yield new ` Things ` posted to reddit
109
109
110
110
Example:
111
111
112
112
``` 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
+ ```
115
122
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 );
121
128
```
122
129
123
130
``` 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
+ });
131
141
```
132
142
133
143
## Development
0 commit comments