Compare commits
No commits in common. "68fdd4e0ce3772353339d503402a474a6b03b932" and "27dce710a6e3c5550cfa84a61067b075453c8ebd" have entirely different histories.
68fdd4e0ce
...
27dce710a6
|
@ -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"}
|
|
@ -21,13 +21,14 @@ export class IPFSClient extends Client {
|
|||
}
|
||||
connectModuleGenerator(method, data) {
|
||||
let pipe = defer();
|
||||
let done = false;
|
||||
const [update, result] = this.connectModule(method, data, (item) => {
|
||||
pipe.resolve(item);
|
||||
});
|
||||
(async () => {
|
||||
const ret = await result;
|
||||
done = true;
|
||||
this.handleError(ret);
|
||||
pipe.resolve(undefined);
|
||||
})();
|
||||
return {
|
||||
abort() {
|
||||
|
@ -38,18 +39,18 @@ export class IPFSClient extends Client {
|
|||
[Symbol.asyncIterator]() {
|
||||
return {
|
||||
async next() {
|
||||
const chunk = await pipe.promise;
|
||||
if (chunk === undefined) {
|
||||
if (done) {
|
||||
return {
|
||||
value: new Uint8Array(),
|
||||
done: true,
|
||||
value: undefined,
|
||||
done,
|
||||
};
|
||||
}
|
||||
const chunk = await pipe.promise;
|
||||
update("next");
|
||||
pipe = defer();
|
||||
return {
|
||||
value: chunk,
|
||||
done: false,
|
||||
done,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
14
src/index.ts
14
src/index.ts
|
@ -38,14 +38,16 @@ export class IPFSClient extends Client {
|
|||
): AbortableGenerator {
|
||||
let pipe = defer<Uint8Array>();
|
||||
|
||||
let done = false;
|
||||
|
||||
const [update, result] = this.connectModule(method, data, (item: any) => {
|
||||
pipe.resolve(item);
|
||||
});
|
||||
|
||||
(async () => {
|
||||
const ret = await result;
|
||||
done = true;
|
||||
this.handleError(ret);
|
||||
pipe.resolve(undefined);
|
||||
})();
|
||||
|
||||
return {
|
||||
|
@ -58,21 +60,21 @@ export class IPFSClient extends Client {
|
|||
[Symbol.asyncIterator]() {
|
||||
return {
|
||||
async next(): Promise<IteratorResult<Uint8Array>> {
|
||||
const chunk = await pipe.promise;
|
||||
if (chunk === undefined) {
|
||||
if (done) {
|
||||
return {
|
||||
value: new Uint8Array(),
|
||||
done: true,
|
||||
value: undefined,
|
||||
done,
|
||||
};
|
||||
}
|
||||
|
||||
const chunk = await pipe.promise;
|
||||
update("next");
|
||||
|
||||
pipe = defer();
|
||||
|
||||
return {
|
||||
value: chunk,
|
||||
done: false,
|
||||
done,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue