This repository was archived by the owner on Mar 21, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 175
Use async functions instead of promises #447
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Overview of the feature request
Use async/await instead of promises for more succinct code.
For example, instead of the following JHipster-generated code
this.rideService()
.retrieve(paginationQuery)
.then(
res => {
this.rides = res.data;
this.totalItems = Number(res.headers['x-total-count']);
this.queryCount = this.totalItems;
this.isFetching = false;
},
err => {
this.isFetching = false;
}
);do this:
try {
const res = await this.rideService().retrieve(paginationQuery);
this.rides = res.data;
this.totalItems = Number(res.headers['x-total-count']);
this.queryCount = this.totalItems;
} finally {
this.isFetching = false;
}Note that I've left out catch for purely aesthetic reasons - it is still actually required.
Motivation for or Use Case
Quoting Google Developers async functions primer:
Async functions are [...] quite frankly marvelous. They allow you to write promise-based code as if it were synchronous, but without blocking the main thread. They make your asynchronous code less "clever" and more readable.
- Checking this box is mandatory (this is just to show you read everything)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers