本文整理汇总了TypeScript中core-js.Promise类的典型用法代码示例。如果您正苦于以下问题:TypeScript Promise类的具体用法?TypeScript Promise怎么用?TypeScript Promise使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Promise类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: checkStatus
private checkStatus(response : Response) : Promise<Response> {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response);
} else {
let error = new Error(response.statusText);
throw error;
}
}
示例2:
.then((response) => {return Promise.resolve(this.mapGitHubMembersToMemberEntityCollection(response))})
示例3: throwError
private throwError(error){
document.write("<p>Ops! something wrong! We are so embarrased..</p>");
console.log(error);
return Promise.reject(error);
}
示例4: displayMembers
// )
// .catch((err) => {
// document.write("Server error");
// });
promises.push(gitHubAPI.getListOfMembers()
.then((response) =>
displayMembers(response))
);
promises.push(gitHubAPI.getListOfRepositories()
.then((response) =>
displayRepositories(response)
));
Promise.all(promises)
.then(results => {
document.write("<p><b>All async calls sucessfully completed</b></p>");
})
.catch((error) => handleError(error));
function displayMembers(members:Array<MemberEntity>)
{
document.write("<p><b>Sample members list:</b></p>")
members.forEach((member) => {
document.write(`<p>${member.login}</p>`);
});
};
function displayRepositories(repositories : Array<RepositoryEntity>)