本文整理汇总了TypeScript中es6-promise.Promise.all方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Promise.all方法的具体用法?TypeScript Promise.all怎么用?TypeScript Promise.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类es6-promise.Promise
的用法示例。
在下文中一共展示了Promise.all方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: allFilesExist
function allFilesExist(files: Array<string>): Promise<any> {
const fs = require('fs');
return Promise.all(files.map(filepath => promised(cb => fs.stat(`${BUILD_PUBLIC_DIR}/${filepath}`, cb), false)))
// make sure that all stats are truthy
.then(stats => stats.reduce((all, current) => all && current, true));
}
示例2: getWidgets
protected async getWidgets(): Promise<HomeWidgets_01_00_00> {
// Using async/await on ES6 promises
let serviceResults = await Promise.all([
this.homeWidgetsService.getExhibitors(),
this.homeWidgetsService.getHistory(),
this.homeWidgetsService.getRegitrationLogin(),
this.homeWidgetsService.getCategories(),
this.homeWidgetsService.getOfficialStores(),
this.homeWidgetsService.getSell(),
this.homeWidgetsService.getSiteInformation(),
this.homeWidgetsService.getTermsAndConditions()
]);
let homeWidgets = new HomeWidgets_01_00_00();
homeWidgets.exhibitors = serviceResults[0];
homeWidgets.history = serviceResults[1];
homeWidgets.registrationLogin = serviceResults[2];
homeWidgets.categories = serviceResults[3];
homeWidgets.officialStores = serviceResults[4];
homeWidgets.sell = serviceResults[5];
homeWidgets.siteInformation = serviceResults[6];
homeWidgets.termsAndConditons = serviceResults[7];
return Promise.resolve(homeWidgets);
}
示例3: it
it('should resolve on read', () => {
return Promise.all([
buf.write('world').should.be.fulfilled,
buf.read().should.eventually.equal('hello'),
buf.read().should.eventually.equal('world')
]);
});
示例4: promised
const writeIndexHtmlUsingManifests = (manifest: Array<string>): Promise<any> =>
Promise.all([
promised(cb => fs.readFile(`${SRC_DIR}/index.dust`, 'utf8', cb)),
promised(cb => mkdirp(BUILD_PUBLIC_DIR, cb)),
])
.then(([content]) => dust.compile(content, 'index'))
.then(dust.loadSource)
.then(() => promised(cb => dust.render('index', { manifest }, cb)))
.then(html => promised(cb => fs.writeFile(`${BUILD_PUBLIC_DIR}/index.html`, html, cb)));
示例5: resolve
return new Promise<CourseTeachers>((resolve, reject) => {
let ans: CourseTeachers = obj;
Promise.all([
]
).then((values) => {
resolve(ans);
}).catch((error) => {
reject(error);
})
})