DEV: Clarify site-setting category-list concurrency protection ()

This commit is contained in:
Daniel Waterworth 2024-02-09 10:14:00 -06:00 committed by GitHub
parent 2af8f5708d
commit 250ce25ca3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -21,14 +21,22 @@ export default class CategoryList extends Component {
return this.args.value.split("|").filter(Boolean); return this.args.value.split("|").filter(Boolean);
} }
async updateSelectedCategories() { async updateSelectedCategories(previousRequest) {
await this.pendingCategoriesRequest; const categories = await Category.asyncFindByIds(this.categoryIds);
this.selectedCategories = await Category.asyncFindByIds(this.categoryIds);
// This is to prevent a race. We want to ensure that the update to
// selectedCategories for this request happens after the update for the
// previous request.
await previousRequest;
this.selectedCategories = categories;
} }
@action @action
valueChanged() { valueChanged() {
this.pendingCategoriesRequest = this.updateSelectedCategories(); const previousRequest = this.pendingCategoriesRequest;
this.pendingCategoriesRequest =
this.updateSelectedCategories(previousRequest);
} }
@action @action