/    Sign up×
Community /Pin to ProfileBookmark

Calling a method in parallel using async/await.

I am using gradle to build localized files. I have total 7 languages to build. Write now I am using async/await to build for the localized files and it is working fine. It is building in a sequence but a single language to build it take approx. 4 minutes to build.

What i want instead of calling the method in a sequence can it be called in parallel, so that the build time can be reduced.
Below is the code snippet:

“`
const configuration = require(path.resolve(“./tools/build-all.configuration.json”)); // Place from where reading all the languages to build

buildVersions(version).then(() => {
console.log(“Building all language is done.”);
});
async function buildVersions(buildId) {
return new Promise(async accept => {

try {
await buildLanguageVersions(
configuration.localeBuildData.availableLocales.map(language => language.code)

);
} catch (es) {
console.error(es);
}
// writing to file and some operation
accept();
});
}

function buildLanguageVersions(buildLanguages) {
return new Promise(async (accept, reject) => {
const allLanguage = [];

for (let language of buildLanguages) {
const ret = await buildALanguage(language);
allLanguage .push(ret);
}
accept(allLanguage );
});
}

function buildALanguage(buildLanguage) {
return new Promise(accept => {
console.log(” Building a language ” + buildLanguage);
const languagePath = path.resolve(`./src/i18n/messages.${buildLanguage}.xlf`);
const languageFile = fs.existsSync(languagePath) ? buildLanguage : “en”;
if (languageFile !== buildLanguage && !fs.existsSync(languagePath)) {
console.error(
“Language file does not exist. Building with english default version.
);
}
//
// Here doing all the operation to build the language file
// and some operation

exec.exec(`${folder} build –configuration=dynamic`, (error, stdout, stderror) => {
if (error) {
throw “Build failed: ” + error;
}
accept(buildLanguage);
});
});
}
“`

Is there any way I can call the _buildALanguage()_ from _buildLanguageVersions()_ in parallel instead calling in sequence.

Error which I am getting:
14:31:17 ERROR in ngcc is already running at process with id 5252.
14:31:17 If you are running multiple builds in parallel then you should pre-process your node_modules via the command line ngcc tool before starting the builds;

I have checked and removes those files but even though everytime I do the build, i get those errors.

Please excuse the typos.

to post a comment

0Be the first to comment 😎

×

Success!

Help @user_alpha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...