Skip to content

Commit

Permalink
Font Library: install fonts in sequence to work around race condition (
Browse files Browse the repository at this point in the history
…#60180)

* Font Library: install fonts in sequence to work around font directory race condition

* Update comment block to coding standards

Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com>

* Fix linting

---------

Co-authored-by: creativecoder <grantmkin@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>
Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: kjnanda <krupajnanda@git.wordpress.org>
Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
  • Loading branch information
11 people authored and bph committed Mar 26, 2024
1 parent 1cd464d commit 671b80a
Showing 1 changed file with 17 additions and 4 deletions.
Expand Up @@ -234,10 +234,23 @@ export function makeFontFacesFormData( font ) {
}

export async function batchInstallFontFaces( fontFamilyId, fontFacesData ) {
const promises = fontFacesData.map( ( faceData ) =>
fetchInstallFontFace( fontFamilyId, faceData )
);
const responses = await Promise.allSettled( promises );
const responses = [];

/*
* Uses the same response format as Promise.allSettled, but executes requests in sequence to work
* around a race condition that can cause an error when the fonts directory doesn't exist yet.
*/
for ( const faceData of fontFacesData ) {
try {
const response = await fetchInstallFontFace(
fontFamilyId,
faceData
);
responses.push( { status: 'fulfilled', value: response } );
} catch ( error ) {
responses.push( { status: 'rejected', reason: error } );
}
}

const results = {
errors: [],
Expand Down

0 comments on commit 671b80a

Please sign in to comment.