Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active October 11, 2022 23:49
Show Gist options
  • Save ajcrites/db1ab9ee6a1ad81c90c4ff74e708d9b2 to your computer and use it in GitHub Desktop.
Save ajcrites/db1ab9ee6a1ad81c90c4ff74e708d9b2 to your computer and use it in GitHub Desktop.
deleteStaleSpecials() {
const specialsDeletionStatus = Promise.allSettled(
this.specials
.filter(({ stale }) => stale)
.map((special) => this.deleteSpecial(special))
);
const rejectedCheckPredicate = ({ status }) => status === 'rejected';
if (specialsDeletionStatus.some(rejectedCheckPredicate) {
throw new Error(`Failed to delete some stale specials: ${
specialsDeletionStatus
.filter(rejectedCheckPredicate)
.reduce((rejectionMessages, { reason }) => rejectionStatusMessages + reason, '')
}`);
}
return specialsDeletionStatus;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment