Skip to content

Commit 2fb95db

Browse files
committed
Add async iterator usage example to README
https://claude.ai/code/session_01Rx48d2xCMjtzmoynPwet77
1 parent a0a3c0e commit 2fb95db

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ feedparser.on('readable', function () {
6262

6363
```
6464

65+
You can also consume feeds using async iteration:
66+
67+
```js
68+
69+
var FeedParser = require('feedparser');
70+
var fetch = require('node-fetch');
71+
72+
async function main() {
73+
var res = await fetch('http://somefeedurl.xml');
74+
if (res.status !== 200) throw new Error('Bad status code');
75+
76+
var feedparser = new FeedParser([options]);
77+
feedparser.on('error', function (error) { throw error; });
78+
res.body.pipe(feedparser);
79+
80+
for await (var item of feedparser) {
81+
console.log(item.title);
82+
}
83+
}
84+
85+
main();
86+
87+
```
88+
6589
You can also check out this nice [working implementation](https://github.com/scripting/feedRead) that demonstrates one way to handle all the hard and annoying stuff. :smiley:
6690

6791
### options

0 commit comments

Comments
 (0)