Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve stream examples with the includes object #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ setTimeout(() => {
stream.close();
}, 30000);

for await (const { data } of stream) {
console.log(data);
for await (const { data, includes } of stream) {
console.log("data", data);
console.log("includes", includes);
}
```

Expand All @@ -122,8 +123,8 @@ these cases. For example:
```js
async function listenForever(streamFactory, dataConsumer) {
try {
for await (const { data } of streamFactory()) {
dataConsumer(data);
for await (const { data, includes } of streamFactory()) {
dataConsumer(data, includes);
}
// The stream has been closed by Twitter. It is usually safe to reconnect.
console.log('Stream disconnected healthily. Reconnecting.');
Expand All @@ -139,7 +140,10 @@ async function listenForever(streamFactory, dataConsumer) {

listenForever(
() => client.stream('tweets/search/stream'),
(data) => console.log(data)
(data, includes) => {
console.log("data", data);
console.log("includes", includes);
}
);
```

Expand Down
2 changes: 1 addition & 1 deletion examples/stream_tweets.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function main() {
}, 30 * 1000);

// Read data from the stream
for await (const { data } of stream) {
for await (const { data, includes } of stream) {
console.log(`${data.id}: ${data.text.replace(/\s/g, ' ')}`);
}

Expand Down