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