本文整理汇总了TypeScript中promise.all函数的典型用法代码示例。如果您正苦于以下问题:TypeScript all函数的具体用法?TypeScript all怎么用?TypeScript all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了all函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(function() {
return Promise.all([
systemjs.import('./src/stores/route-store'),
systemjs.import('./src/dispatcher')
]).then(function(modules) {
routeStore = new modules[0].routeStore.constructor();
dispatcher = modules[1].dispatcher;
});
});
示例2: expect
db.collection("coll_group_1").then(coll => {
Promise.all([
coll.insert({
_id: 1111,
name: 'eeee',
age: 22
}, {chain: true}),
coll.insert({
_id: 1112,
name: 'dddd',
age: 23
}, {chain: true}),
coll.insert({
_id: 1113,
name: 'cccc',
age: 22
}, {chain: true}),
coll.insert({
_id: 1114,
name: 'bbbb',
age: 25
}, {chain: true}),
coll.insert({
_id: 1115,
name: 'aaaa',
age: 23
})
]).then(() => {
var docs = coll.aggregate([{
$group: {
_id: "$age",
count: {
$sum: 1
},
total_id: {
$sum: "$_id"
},
total_age: {
$sum: '$age'
}
}
}]);
expect(docs).to.exist;
expect(docs).to.be.instanceof(Array);
expect(docs).to.have.length(3);
done();
});
});
示例3: getResult
getResult(): Promise.IThenable<User> {
if (_.isUndefined(this.passwordPromise)) {
throw new Error("You need to set password first");
}
return Promise.all([
this.passwordPromise,
]).then(([password]) => {
return {
id: this.email,
email: this.email,
password: password,
salt: this.salt
}
});
}
示例4: reject
.then((token) => {
const promises: Array<Promise.IThenable<ISeverityCountResult>> = [];
[SeverityType.Low, SeverityType.Medium, SeverityType.High, SeverityType.Critical].forEach((severity) => {
const q = qs.stringify({
fields: 'severityString',
limit: 1,
filters: `severity:${severity}+isSuppressed:false`,
excludeFilters: true
});
promises.push(
new Promise<ISeverityCountResult>((resolve, reject) => {
msg.http(FoDApiHelper.getApiUri(`/api/v3/releases/${releaseId}/vulnerabilities?${q}`))
.headers({
'authorization': `Bearer ${token}`,
'content-type': 'application/octet-stream'
})
.get()((err: any, res: any, body: any) => {
if (err)
return reject(err);
const result = JSON.parse(body);
if (result && result.totalCount && result.items) {
return resolve({ severityId: severity, severityType: result.items[0].severityString, count: result.totalCount });
}
return resolve(null);
});
}));
});
return Promise.all(promises);
})