Skip to content

Commit

Permalink
fix pagination logic
Browse files Browse the repository at this point in the history
  • Loading branch information
agola11 committed Jul 2, 2024
1 parent 1809ac4 commit 70ee9fe
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ export class Client {
): AsyncIterable<T[]> {
let offset = Number(queryParams.get("offset")) || 0;
const limit = Number(queryParams.get("limit")) || 100;
const limitSet = queryParams.has("limit");
while (true) {
queryParams.set("offset", String(offset));
queryParams.set("limit", String(limit));
Expand All @@ -595,10 +594,6 @@ export class Client {
}
yield items;

if (limitSet && items.length === limit) {
break;
}

if (items.length < limit) {
break;
}
Expand Down Expand Up @@ -2248,11 +2243,18 @@ export class Client {
if (filter !== undefined) {
params.append("filter", filter);
}
let i = 0;
for await (const examples of this._getPaginated<Example>(
"/examples",
params
)) {
yield* examples;
for (const example of examples) {
yield example;
i++;
}
if (limit !== undefined && i >= limit) {
break;
}
}
}

Expand Down

0 comments on commit 70ee9fe

Please sign in to comment.