How To Array.map Chain Off Of Async Await?
How can I run Array.map off of an await? const CLASS_PATH = 'User/matt/Github/project'; const PACKAGE_JSON = 'package.json'; const walk = async path => { let dirs = []; for
Solution 1:
Brackets can always be used to change operator predescendence:
(await walk(CLASS_PATH)).map(/*...*/)
Solution 2:
You can also use Promise. So in your case:
const packagePaths = awaitPromise.all(walk(CLASS_PATH).map(async (item): Promise<number> => {
awaitjoin(CLASS_PATH, pkgName, PACKAGE_JSON);
}));
The Promise.all(iterable) method returns a promise that resolves when all of the promises in the iterable argument have resolved, or rejects with the reason of the first passed promise that rejects.
Post a Comment for "How To Array.map Chain Off Of Async Await?"