From 18c33af96ac2bae01030294ba5f9251a7de14020 Mon Sep 17 00:00:00 2001 From: AnyG <49390906+AnyGCn@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:42:29 +0000 Subject: [PATCH] Fix async code issue. --- docs/develop/dapps/tutorials/collection-minting.md | 4 ++-- .../current/develop/dapps/tutorials/collection-minting.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/develop/dapps/tutorials/collection-minting.md b/docs/develop/dapps/tutorials/collection-minting.md index 9f53d405b1..8b0149144a 100644 --- a/docs/develop/dapps/tutorials/collection-minting.md +++ b/docs/develop/dapps/tutorials/collection-minting.md @@ -284,7 +284,7 @@ This is really inconvenient and wrong, so let's write a function that will do th export async function updateMetadataFiles(metadataFolderPath: string, imagesIpfsHash: string): Promise { const files = readdirSync(metadataFolderPath); - files.forEach(async (filename, index) => { + await Promise.all(files.map(async (filename, index) => { const filePath = path.join(metadataFolderPath, filename) const file = await readFile(filePath); @@ -295,7 +295,7 @@ export async function updateMetadataFiles(metadataFolderPath: string, imagesIpfs : `ipfs://${imagesIpfsHash}/logo.jpg`; await writeFile(filePath, JSON.stringify(metadata)); - }); + })); } ``` Here we firstly read all of the files in specified folder: diff --git a/i18n/mandarin/docusaurus-plugin-content-docs/current/develop/dapps/tutorials/collection-minting.md b/i18n/mandarin/docusaurus-plugin-content-docs/current/develop/dapps/tutorials/collection-minting.md index 836a0fb91a..27983d1082 100644 --- a/i18n/mandarin/docusaurus-plugin-content-docs/current/develop/dapps/tutorials/collection-minting.md +++ b/i18n/mandarin/docusaurus-plugin-content-docs/current/develop/dapps/tutorials/collection-minting.md @@ -282,7 +282,7 @@ export async function uploadFolderToIPFS(folderPath: string): Promise { export async function updateMetadataFiles(metadataFolderPath: string, imagesIpfsHash: string): Promise { const files = readdirSync(metadataFolderPath); - files.forEach(async (filename, index) => { + await Promise.all(files.map(async (filename, index) => { const filePath = path.join(metadataFolderPath, filename) const file = await readFile(filePath); @@ -293,7 +293,7 @@ export async function updateMetadataFiles(metadataFolderPath: string, imagesIpfs : `ipfs://${imagesIpfsHash}/logo.jpg`; await writeFile(filePath, JSON.stringify(metadata)); - }); + })); } ``` 这里我们首先读取指定文件夹中的所有文件: