feeds.paginate()
Automatically paginate through all feeds using async iteration.
Signature
feeds.paginate(options?: PaginateOptions): AsyncGenerator<Feed, void, unknown>Parameters
options
- Type:
PaginateOptions(optional)
interface PaginateOptions {
limit?: number; // Items per page (default: 50)
category_id?: string; // Filter by category
tags?: string[]; // Filter by tags
search?: string; // Search term
sort?: 'created_at' | 'updated_at' | 'total_entries' | 'total_revenue';
order?: 'asc' | 'desc';
}Returns
- Type:
AsyncGenerator<Feed, void, unknown>
Returns an async generator that yields individual Feed objects.
Usage
Basic Example
// Iterate through all feeds
for await (const feed of grapevine.feeds.paginate()) {
console.log(feed.name);
}With Filters
// Paginate through tech feeds
for await (const feed of grapevine.feeds.paginate({
tags: ['technology'],
sort: 'total_revenue',
order: 'desc'
})) {
console.log(`${feed.name}: ${feed.total_revenue}`);
}Collect All Results
// Collect all feeds into an array
async function getAllFeeds() {
const allFeeds: Feed[] = [];
for await (const feed of grapevine.feeds.paginate()) {
allFeeds.push(feed);
}
return allFeeds;
}
// Or using Array.from with async iterables
const allFeeds = await Array.fromAsync(
grapevine.feeds.paginate()
);Process in Batches
async function processFeedsBatch() {
const batch: Feed[] = [];
const batchSize = 10;
for await (const feed of grapevine.feeds.paginate()) {
batch.push(feed);
if (batch.length === batchSize) {
await processBatch(batch);
batch.length = 0;
}
}
// Process remaining feeds
if (batch.length > 0) {
await processBatch(batch);
}
}Early Termination
// Stop after finding specific feed
async function findFeedByCondition() {
for await (const feed of grapevine.feeds.paginate()) {
if (feed.total_entries > 100 && feed.tags.includes('crypto')) {
return feed; // Stops iteration
}
}
return null;
}With Progress Tracking
async function paginateWithProgress() {
let count = 0;
for await (const feed of grapevine.feeds.paginate({
limit: 25
})) {
count++;
console.log(`Processing feed ${count}: ${feed.name}`);
// Process feed
await processF feed(feed);
}
console.log(`Processed ${count} total feeds`);
}Behind the Scenes
This method:
- Makes initial request to get first page
- Yields feeds one by one from current page
- Automatically fetches next page when needed
- Continues until no more pages available
- Handles pagination state internally
Error Handling
try {
for await (const feed of grapevine.feeds.paginate()) {
console.log(feed.name);
}
} catch (error) {
console.error('Pagination error:', error);
}
// With individual error handling
async function safePaginate() {
try {
for await (const feed of grapevine.feeds.paginate()) {
try {
await processFeed(feed);
} catch (feedError) {
console.error(`Error processing ${feed.id}:`, feedError);
// Continue with next feed
}
}
} catch (paginationError) {
console.error('Pagination failed:', paginationError);
}
}Notes
- Memory Efficient: Yields one feed at a time
- Automatic: Handles page fetching automatically
- Lazy Loading: Only fetches pages as needed
- Interruptible: Can break/return early to stop iteration
- Authentication: Optional - works with public feeds
Related
- feeds.list() - Manual pagination control
- entries.paginate() - Paginate entries
- feeds.myFeeds() - Paginate your feeds