Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created December 21, 2024 04:31
Show Gist options
  • Save YonatanKra/1ba66ef769e0ed54ef98635be0a0bb75 to your computer and use it in GitHub Desktop.
Save YonatanKra/1ba66ef769e0ed54ef98635be0a0bb75 to your computer and use it in GitHub Desktop.
async streamPosts(handle: string, onUpdate: (results: any) => any) {
while (true) {
try {
const result = await this.#agent.getAuthorFeed({
actor: handle,
limit: 20,
cursor: undefined,
filter: 'posts_with_media'
});
if (!result.data?.feed?.length) {
console.log('No more posts');
onUpdate({ done: true });
break;
}
onUpdate({result: result.data.feed, done: !result.data.cursor});
if (!result.data.cursor) {
break;
}
} catch (e) {
await new Promise(res => setTimeout(res, 5000));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment