Loading src/vocab/lookup.test.ts +13 −0 Original line number Diff line number Diff line Loading @@ -130,6 +130,19 @@ test("traverseCollection()", async () => { new Note({ content: "This is a third simple note" }), ], ); assertEquals( await toArray( traverseCollection(pagedCollection, { ...options, interval: { milliseconds: 250 }, }), ), [ new Note({ content: "This is a simple note" }), new Note({ content: "This is another simple note" }), new Note({ content: "This is a third simple note" }), ], ); }); // cSpell: ignore gildong src/vocab/lookup.ts +12 −0 Original line number Diff line number Diff line import { getLogger } from "@logtape/logtape"; import { delay } from "@std/async/delay"; import { type DocumentLoader, fetchDocumentLoader, Loading Loading @@ -129,6 +130,14 @@ export interface TraverseCollectionOptions { * The context loader for loading remote JSON-LD contexts. */ contextLoader?: DocumentLoader; /** * The interval to wait between fetching pages. Zero or negative * values will disable the interval. Disabled by default. * * @default `{ seconds: 0 }` */ interval?: Temporal.Duration | Temporal.DurationLike; } /** Loading Loading @@ -160,11 +169,14 @@ export async function* traverseCollection( yield item; } } else { const interval = Temporal.Duration.from(options.interval ?? { seconds: 0 }) .total("millisecond"); let page = await collection.getFirst(options); while (page != null) { for await (const item of page.getItems(options)) { yield item; } if (interval > 0) await delay(interval); page = await page.getNext(options); } } Loading Loading
src/vocab/lookup.test.ts +13 −0 Original line number Diff line number Diff line Loading @@ -130,6 +130,19 @@ test("traverseCollection()", async () => { new Note({ content: "This is a third simple note" }), ], ); assertEquals( await toArray( traverseCollection(pagedCollection, { ...options, interval: { milliseconds: 250 }, }), ), [ new Note({ content: "This is a simple note" }), new Note({ content: "This is another simple note" }), new Note({ content: "This is a third simple note" }), ], ); }); // cSpell: ignore gildong
src/vocab/lookup.ts +12 −0 Original line number Diff line number Diff line import { getLogger } from "@logtape/logtape"; import { delay } from "@std/async/delay"; import { type DocumentLoader, fetchDocumentLoader, Loading Loading @@ -129,6 +130,14 @@ export interface TraverseCollectionOptions { * The context loader for loading remote JSON-LD contexts. */ contextLoader?: DocumentLoader; /** * The interval to wait between fetching pages. Zero or negative * values will disable the interval. Disabled by default. * * @default `{ seconds: 0 }` */ interval?: Temporal.Duration | Temporal.DurationLike; } /** Loading Loading @@ -160,11 +169,14 @@ export async function* traverseCollection( yield item; } } else { const interval = Temporal.Duration.from(options.interval ?? { seconds: 0 }) .total("millisecond"); let page = await collection.getFirst(options); while (page != null) { for await (const item of page.getItems(options)) { yield item; } if (interval > 0) await delay(interval); page = await page.getNext(options); } } Loading