Skip to content

Commit

Permalink
fix: uses promises array to settle all getParcelContent calls
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrdd committed Mar 10, 2023
1 parent a667f4d commit 71f0c24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions components/parcels/Foreclosure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function Foreclosure(props: ForeclosureProps) {

(async () => {
const _parcels: Bid[] = [];
const promises = [];
let promises = [];

for (const parcel of data.geoWebParcels) {
const licenseDiamondAddress = parcel.licenseDiamond;
Expand Down Expand Up @@ -142,9 +142,10 @@ function Foreclosure(props: ForeclosureProps) {
await Promise.allSettled(promises);

const foreclosedParcels = _parcels.splice(0, MAX_LIST_SIZE);
promises = [];

for (const foreclosedParcel of foreclosedParcels) {
Promise.allSettled([
promises.push(
(async () => {
const parcelContent = await getParcelContent(
registryContract.address.toLowerCase(),
Expand All @@ -158,10 +159,12 @@ function Foreclosure(props: ForeclosureProps) {
: `Parcel ${foreclosedParcel.parcelId}`;

foreclosedParcel.name = name;
})(),
]);
})()
);
}

await Promise.allSettled(promises);

if (isMounted) {
const sorted = sortParcels(foreclosedParcels);

Expand Down
11 changes: 7 additions & 4 deletions components/parcels/NeedsTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function NeedsTransfer(props: NeedsTransferProps) {

(async () => {
const _parcels: Bid[] = [];
const promises = [];
let promises = [];

for (const parcel of data.geoWebParcels) {
const pendingBid = parcel.pendingBid;
Expand Down Expand Up @@ -151,9 +151,10 @@ function NeedsTransfer(props: NeedsTransferProps) {
await Promise.allSettled(promises);

const needsTransferParcels = _parcels.splice(0, MAX_LIST_SIZE);
promises = [];

for (const needsTransferParcel of needsTransferParcels) {
Promise.allSettled([
promises.push(
(async () => {
const parcelContent = await getParcelContent(
registryContract.address.toLowerCase(),
Expand All @@ -167,10 +168,12 @@ function NeedsTransfer(props: NeedsTransferProps) {
: `Parcel ${needsTransferParcel.parcelId}`;

needsTransferParcel.name = name;
})(),
]);
})()
);
}

await Promise.allSettled(promises);

if (isMounted) {
const sorted = sortParcels(needsTransferParcels);

Expand Down

0 comments on commit 71f0c24

Please sign in to comment.