From d79086ad00a9c050f1af72b5a13e029ce7a545a7 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 22 Aug 2022 03:21:22 -0400 Subject: [PATCH] *handleBuffer should return a promise to operate in order --- src/contentProviders/ipfsProvider.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/contentProviders/ipfsProvider.ts b/src/contentProviders/ipfsProvider.ts index 7a79b16..8b35afa 100644 --- a/src/contentProviders/ipfsProvider.ts +++ b/src/contentProviders/ipfsProvider.ts @@ -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,15 +307,20 @@ 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()); + }); }); return {}; @@ -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) {