Skip to content

Commit

Permalink
[mobile] Fix startup tasks synchronization
Browse files Browse the repository at this point in the history
Ensure that copyAssetsToFolder finishes before startupTasks reports as done.
This doesn't solve any of my current experimental problems, but I happened to notice that it wasn't awaiting the finish of the copies properly, so just fixing that anyway!
It's needed to fix some unlucky person's future problem anyway.
  • Loading branch information
jsubloom committed Sep 7, 2023
1 parent 60e2bb7 commit a18a8aa
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/mobile/src/util/StartupTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,35 @@ export default async function startupTasks(): Promise<void> {
}

async function loadWebBundleAsync() {
copyAssetsToFolder(Locations.WebRootFolder, webBundleAssets);
await copyAssetsToFolderAsync(Locations.WebRootFolder, webBundleAssets);
}

async function loadBloomPlayerAsync() {
copyAssetsToFolder(
await copyAssetsToFolderAsync(
Path.join(Locations.WebRootFolder, "bloom-player"),
bloomPlayerAssets
);
}

async function copyAssetsToFolder(destFolder: string, assets: Asset[]) {
async function copyAssetsToFolderAsync(destFolder: string, assets: Asset[]) {
// Clearing the folder is optional in production,
// but useful in development to ensure we're starting from a clean folder.
await FileSystem.deleteAsync(destFolder, {
idempotent: true,
});
await ensureFolderAsync(destFolder);
const copyPromises = assets.map((asset) => {
const copyPromises = assets.map(async (asset) => {
// Precondition: Right now we assume that the assets are all in a single flat folder
// with no subfolders. This assumption simplifies the code here.
const extension = asset.type === "jsAsset" ? "js" : asset.type;
const destination = `${destFolder}/${asset.name}.${extension}`;
console.log({ destination });

return copyAssetAsync({
await copyAssetAsync({
asset,
to: destination,
});

console.log({ finishedCopying: destination });
});

// ENHANCE: catch if Promise.all rejects.
Expand Down

0 comments on commit a18a8aa

Please sign in to comment.