Compare commits

..

2 Commits

3 changed files with 13 additions and 16 deletions

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAW,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEnE,UAAU,kBAAkB;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,QAAQ,EAAE,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;CAC3C;AAED,qBAAa,UAAW,SAAQ,MAAM;IACvB,KAAK;IAIL,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAItD,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,kBAAkB;IAIjE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,kBAAkB;IAI7D,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlC,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C,OAAO,CAAC,sBAAsB;CAmD/B;AAED,eAAO,MAAM,YAAY,8BAGxB,CAAC"} {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAW,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEnE,UAAU,kBAAkB;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,QAAQ,EAAE,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;CAC3C;AAED,qBAAa,UAAW,SAAQ,MAAM;IACvB,KAAK;IAIL,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAItD,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,kBAAkB;IAIjE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,kBAAkB;IAI7D,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlC,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C,OAAO,CAAC,sBAAsB;CAiD/B;AAED,eAAO,MAAM,YAAY,8BAGxB,CAAC"}

13
dist/index.js vendored
View File

@ -21,14 +21,13 @@ export class IPFSClient extends Client {
} }
connectModuleGenerator(method, data) { connectModuleGenerator(method, data) {
let pipe = defer(); let pipe = defer();
let done = false;
const [update, result] = this.connectModule(method, data, (item) => { const [update, result] = this.connectModule(method, data, (item) => {
pipe.resolve(item); pipe.resolve(item);
}); });
(async () => { (async () => {
const ret = await result; const ret = await result;
done = true;
this.handleError(ret); this.handleError(ret);
pipe.resolve(undefined);
})(); })();
return { return {
abort() { abort() {
@ -39,18 +38,18 @@ export class IPFSClient extends Client {
[Symbol.asyncIterator]() { [Symbol.asyncIterator]() {
return { return {
async next() { async next() {
if (done) { const chunk = await pipe.promise;
if (chunk === undefined) {
return { return {
value: undefined, value: new Uint8Array(),
done, done: true,
}; };
} }
const chunk = await pipe.promise;
update("next"); update("next");
pipe = defer(); pipe = defer();
return { return {
value: chunk, value: chunk,
done, done: false,
}; };
}, },
}; };

View File

@ -38,16 +38,14 @@ export class IPFSClient extends Client {
): AbortableGenerator { ): AbortableGenerator {
let pipe = defer<Uint8Array>(); let pipe = defer<Uint8Array>();
let done = false;
const [update, result] = this.connectModule(method, data, (item: any) => { const [update, result] = this.connectModule(method, data, (item: any) => {
pipe.resolve(item); pipe.resolve(item);
}); });
(async () => { (async () => {
const ret = await result; const ret = await result;
done = true;
this.handleError(ret); this.handleError(ret);
pipe.resolve(undefined);
})(); })();
return { return {
@ -60,21 +58,21 @@ export class IPFSClient extends Client {
[Symbol.asyncIterator]() { [Symbol.asyncIterator]() {
return { return {
async next(): Promise<IteratorResult<Uint8Array>> { async next(): Promise<IteratorResult<Uint8Array>> {
if (done) { const chunk = await pipe.promise;
if (chunk === undefined) {
return { return {
value: undefined, value: new Uint8Array(),
done, done: true,
}; };
} }
const chunk = await pipe.promise;
update("next"); update("next");
pipe = defer(); pipe = defer();
return { return {
value: chunk, value: chunk,
done, done: false,
}; };
}, },
}; };