Compare commits

..

No commits in common. "68fdd4e0ce3772353339d503402a474a6b03b932" and "27dce710a6e3c5550cfa84a61067b075453c8ebd" have entirely different histories.

3 changed files with 16 additions and 13 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;CAiD/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;CAmD/B;AAED,eAAO,MAAM,YAAY,8BAGxB,CAAC"}

13
dist/index.js vendored
View File

@ -21,13 +21,14 @@ 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() {
@ -38,18 +39,18 @@ export class IPFSClient extends Client {
[Symbol.asyncIterator]() { [Symbol.asyncIterator]() {
return { return {
async next() { async next() {
const chunk = await pipe.promise; if (done) {
if (chunk === undefined) {
return { return {
value: new Uint8Array(), value: undefined,
done: true, done,
}; };
} }
const chunk = await pipe.promise;
update("next"); update("next");
pipe = defer(); pipe = defer();
return { return {
value: chunk, value: chunk,
done: false, done,
}; };
}, },
}; };

View File

@ -38,14 +38,16 @@ 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 {
@ -58,21 +60,21 @@ export class IPFSClient extends Client {
[Symbol.asyncIterator]() { [Symbol.asyncIterator]() {
return { return {
async next(): Promise<IteratorResult<Uint8Array>> { async next(): Promise<IteratorResult<Uint8Array>> {
const chunk = await pipe.promise; if (done) {
if (chunk === undefined) {
return { return {
value: new Uint8Array(), value: undefined,
done: true, done,
}; };
} }
const chunk = await pipe.promise;
update("next"); update("next");
pipe = defer(); pipe = defer();
return { return {
value: chunk, value: chunk,
done: false, done,
}; };
}, },
}; };