本文整理匯總了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);
})