Skip to content

Commit

Permalink
Return Promise rather than an async generator
Browse files Browse the repository at this point in the history
Return Promise rather than an async generator
  • Loading branch information
Shreyaschorge authored Nov 1, 2023
2 parents b9056ea + 4f5111f commit 614ff1e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/nodejs-sdk",
"version": "0.6.1",
"version": "0.6.2",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
42 changes: 18 additions & 24 deletions src/neynar-api/neynar-v2-api/neynar-api-v2-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,37 +259,31 @@ export class NeynarV2APIClient {
* See [Neynar documentation](https://docs.neynar.com/reference/feed)
*
*/
public async *fetchFeedPage(
public async fetchFeedPage(
fid: number,
options?: {
feedType?: FeedType;
filterType?: FilterType;
fids?: string;
parentUrl?: string;
pageSize?: number;
limit?: number;
cursor?: string;
}
): AsyncGenerator<CastWithInteractions[], void, undefined> {
let cursor: string | undefined;

while (true) {
const response = await this.apis.feed.feed({
feedType: options?.feedType,
filterType: options?.filterType,
fid: fid,
fids: options?.fids,
parentUrl: options?.parentUrl,
cursor: cursor,
limit: options?.pageSize,
});

// yield current page of casts
yield response.data.casts;
): Promise<{ casts: CastWithInteractions[]; nextCursor: string | null }> {
const response = await this.apis.feed.feed({
feedType: options?.feedType,
filterType: options?.filterType,
fid: fid,
fids: options?.fids,
parentUrl: options?.parentUrl,
cursor: options?.cursor,
limit: options?.limit,
});

// prep for next page
if (response.data.next.cursor === null) {
break;
}
cursor = response.data.next.cursor;
}
// Return the current page of casts and the next cursor
return {
casts: response.data.casts,
nextCursor: response.data.next.cursor,
};
}
}

0 comments on commit 614ff1e

Please sign in to comment.