diff --git a/src/index.ts b/src/index.ts index 017120c..58b2485 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import { CatOptions, LsOptions, StatOptions } from "@helia/unixfs"; interface AbortableGenerator { abort: () => void; - iterable: AsyncGenerator; + iterable: () => AsyncIterable; } export class IPFSClient extends Client { @@ -36,7 +36,7 @@ export class IPFSClient extends Client { method: string, data: any ): AbortableGenerator { - const pipe = defer(); + let pipe = defer(); let done = false; @@ -52,15 +52,27 @@ export class IPFSClient extends Client { return { abort() { - update(); + update("abort"); }, - // @ts-ignore - iterable: async function* (): AsyncGenerator { - // @ts-ignore - const iterator = (await pipe.promise)[Symbol.asyncIterator](); - for await (const value of iterator) { - yield value as object; - } + + iterable(): AsyncIterable { + return { + [Symbol.asyncIterator]() { + return { + async next(): Promise> { + const chunk = await pipe.promise; + update("next"); + + pipe = defer(); + + return { + value: chunk, + done: true as const, + }; + }, + }; + }, + }; }, }; }