Redundant use of
await
on a return value134 return await this.getGreenButtonEndpoint('/ReadServiceStatus');
135 }
136 async getApplicationInformation(appId) {
137 return await this.getGreenButtonEndpoint(`/ApplicationInformation/${appId}`);138 }
139}
140export { helpers } from '@cityssm/green-button-parser';
Redundant use of
await
on a return value131 return await this.getGreenButtonEndpoint(`/Batch/Subscription/${authorizationId}/UsagePoint/${meterId}`, formatDateTimeFiltersParameters(dateTimeFilters));
132 }
133 async getServiceStatus() {
134 return await this.getGreenButtonEndpoint('/ReadServiceStatus');135 }
136 async getApplicationInformation(appId) {
137 return await this.getGreenButtonEndpoint(`/ApplicationInformation/${appId}`);
Redundant use of
await
on a return value128 return await this.getGreenButtonEndpoint(`/Batch/Subscription/${authorizationId}`, formatDateTimeFiltersParameters(dateTimeFilters));
129 }
130 async getBatchSubscriptionsByMeter(authorizationId, meterId, dateTimeFilters) {
131 return await this.getGreenButtonEndpoint(`/Batch/Subscription/${authorizationId}/UsagePoint/${meterId}`, formatDateTimeFiltersParameters(dateTimeFilters));132 }
133 async getServiceStatus() {
134 return await this.getGreenButtonEndpoint('/ReadServiceStatus');
Redundant use of
await
on a return value125 return await this.getGreenButtonEndpoint(`/RetailCustomer/${authorizationId}/Customer/${customerId}/CustomerAccount/${customerAccountId}/CustomerAgreement`);
126 }
127 async getBatchSubscriptionsByAuthorization(authorizationId, dateTimeFilters) {
128 return await this.getGreenButtonEndpoint(`/Batch/Subscription/${authorizationId}`, formatDateTimeFiltersParameters(dateTimeFilters));129 }
130 async getBatchSubscriptionsByMeter(authorizationId, meterId, dateTimeFilters) {
131 return await this.getGreenButtonEndpoint(`/Batch/Subscription/${authorizationId}/UsagePoint/${meterId}`, formatDateTimeFiltersParameters(dateTimeFilters));
Redundant use of
await
on a return value122 return await this.getGreenButtonEndpoint(`/RetailCustomer/${authorizationId}/Customer/${customerId}/CustomerAccount`);
123 }
124 async getCustomerAgreements(authorizationId, customerId, customerAccountId) {
125 return await this.getGreenButtonEndpoint(`/RetailCustomer/${authorizationId}/Customer/${customerId}/CustomerAccount/${customerAccountId}/CustomerAgreement`);126 }
127 async getBatchSubscriptionsByAuthorization(authorizationId, dateTimeFilters) {
128 return await this.getGreenButtonEndpoint(`/Batch/Subscription/${authorizationId}`, formatDateTimeFiltersParameters(dateTimeFilters));
Redundant use of
await
on a return value119 return await this.getGreenButtonEndpoint(`/RetailCustomer/${authorizationId}/Customer`);
120 }
121 async getCustomerAccounts(authorizationId, customerId) {
122 return await this.getGreenButtonEndpoint(`/RetailCustomer/${authorizationId}/Customer/${customerId}/CustomerAccount`);123 }
124 async getCustomerAgreements(authorizationId, customerId, customerAccountId) {
125 return await this.getGreenButtonEndpoint(`/RetailCustomer/${authorizationId}/Customer/${customerId}/CustomerAccount/${customerAccountId}/CustomerAgreement`);
Redundant use of
await
on a return value116 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/ElectricPowerQualitySummary`);
117 }
118 async getCustomers(authorizationId) {
119 return await this.getGreenButtonEndpoint(`/RetailCustomer/${authorizationId}/Customer`);120 }
121 async getCustomerAccounts(authorizationId, customerId) {
122 return await this.getGreenButtonEndpoint(`/RetailCustomer/${authorizationId}/Customer/${customerId}/CustomerAccount`);
Redundant use of
await
on a return value113 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/UsageSummary`);
114 }
115 async getElectricPowerQualitySummaries(authorizationId, meterId) {
116 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/ElectricPowerQualitySummary`);117 }
118 async getCustomers(authorizationId) {
119 return await this.getGreenButtonEndpoint(`/RetailCustomer/${authorizationId}/Customer`);
Redundant use of
await
on a return value110 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/MeterReading/${readingId}/IntervalBlock`);
111 }
112 async getUsageSummaries(authorizationId, meterId) {
113 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/UsageSummary`);114 }
115 async getElectricPowerQualitySummaries(authorizationId, meterId) {
116 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/ElectricPowerQualitySummary`);
Redundant use of
await
on a return value107 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/MeterReading`);
108 }
109 async getIntervalBlocks(authorizationId, meterId, readingId) {
110 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/MeterReading/${readingId}/IntervalBlock`);111 }
112 async getUsageSummaries(authorizationId, meterId) {
113 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/UsageSummary`);
Redundant use of
await
on a return value104 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint`);
105 }
106 async getMeterReadings(authorizationId, meterId) {
107 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/MeterReading`);108 }
109 async getIntervalBlocks(authorizationId, meterId, readingId) {
110 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/MeterReading/${readingId}/IntervalBlock`);
Redundant use of
await
on a return value101 return await this.getGreenButtonEndpoint(`/Authorization/${authorizationId}`);
102 }
103 async getUsagePoints(authorizationId) {
104 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint`);105 }
106 async getMeterReadings(authorizationId, meterId) {
107 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint/${meterId}/MeterReading`);
Redundant use of
await
on a return value 98 return await this.getGreenButtonEndpoint('/Authorization');
99 }
100 async getAuthorization(authorizationId) {
101 return await this.getGreenButtonEndpoint(`/Authorization/${authorizationId}`);102 }
103 async getUsagePoints(authorizationId) {
104 return await this.getGreenButtonEndpoint(`/Subscription/${authorizationId}/UsagePoint`);
Redundant use of
await
on a return value 95 return await this.getGreenButtonHttpsLink(`${this.#configuration.baseUrl}espi/1_1/resource${greenButtonEndpoint}`, getParameters);
96 }
97 async getAuthorizations() {
98 return await this.getGreenButtonEndpoint('/Authorization'); 99 }
100 async getAuthorization(authorizationId) {
101 return await this.getGreenButtonEndpoint(`/Authorization/${authorizationId}`);
Redundant use of
await
on a return value 92 };
93 }
94 async getGreenButtonEndpoint(greenButtonEndpoint, getParameters) {
95 return await this.getGreenButtonHttpsLink(`${this.#configuration.baseUrl}espi/1_1/resource${greenButtonEndpoint}`, getParameters); 96 }
97 async getAuthorizations() {
98 return await this.getGreenButtonEndpoint('/Authorization');
Description
Returning an awaited value (like with return await f()
) has two problems:
It queues an extra microtask, blocking the callstack until
return
is executed.try
blocks only catch a rejected promise if itsawait
ed.return await
may introduce unexpected hidden control-flow when handling errors.
Bad Practice
async function getUserByName(name: string) {
// find() returns a Promise<User | null >.
// This promise should be `await`ed by the caller of `getUserByName`.
return await db.users.find({ userName: name })
}
Recommended
async function getUserByName(name: string) {
// find() returns a Promise<User | null >.
return db.users.find({ userName: name })
}
// OR:
async function getUserByName(name: string) {
// If we must `await` the return-value in this function
// it's better to do it this way. This is more performant:
const user = await db.users.find({ userName: name })
return user;
}