*handleBuffer should return a promise to operate in order

This commit is contained in:
Derrick Hammer 2022-08-22 03:21:22 -04:00
parent eb65cc6b10
commit d79086ad00
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 6 deletions

View File

@ -282,7 +282,7 @@ export default class IpfsProvider extends BaseProvider {
const handleBuffer = () => {
if (buffer.length) {
filterPromise.then(() => {
return filterPromise.then(() => {
streamPromise = streamPromise.then(() => {
let mode = contentModes[contentType as string];
buffer = buffer.map((item: Uint8Array | ArrayBuffer) => {
@ -307,14 +307,19 @@ export default class IpfsProvider extends BaseProvider {
});
});
}
return Promise.resolve();
};
if (cachedPage) {
// @ts-ignore
cachedPage.data.arrayBuffer().then((data: ArrayBuffer) => {
// @ts-ignore
receiveUpdate(new Uint8Array(data))?.then(() => {
handleBuffer();
filterPromise.then(() => filter.close());
receiveUpdate(new Uint8Array(data))
?.then(() => {
return handleBuffer();
})
.then(() => {
return filterPromise.then(() => filter.close());
});
});
@ -324,8 +329,8 @@ export default class IpfsProvider extends BaseProvider {
// @ts-ignore
fetchMethod?.(hash, urlPath, receiveUpdate)
.then(() => streamPromise)
.then(() => handleBuffer())
.then(() => {
handleBuffer();
filterPromise.then(() => streamPromise).then(() => filter.close());
resp = resp as StatFileResponse;
if (resp.size <= MAX_CACHE_SIZE) {