return await
function found JS-0111await
on a return value569 }
570 ];
571
572 return await this.updateWorkItem(config, patchDoc);573 }
574
575 async updateWorkItem(config, patchDoc) {
await
on a return value548 }
549 ];
550
551 return await this.updateWorkItem(config, patchDoc);552 }
553
554 async addComment(config) {
await
on a return value530 value: `GitHub issue #${config.issue.number}: <a href="${this.cleanUrl(config.issue.url)}" target="_new">${config.issue.title}</a> in <a href="${this.cleanUrl(config.issue.repository_url)}" target="_blank">${config.repository.full_name}</a> assigned to '${config.assignee.login}' by <a href="${config.issue.user.html_url}" target="_blank">${config.issue.user.login}</a>`
531 });
532
533 return await this.updateWorkItem(config, patchDoc);534 }
535
536 async unassignWorkItem(config) {
await
on a return value502 }
503 ];
504
505 return await this.updateWorkItem(config, patchDoc);506 });
507 }
508
await
on a return value477 }
478 ];
479
480 return await this.updateWorkItem(config, patchDoc);481 }
482
483 async unlabelWorkItem(config) {
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 its await
ed. return await
may introduce unexpected hidden control-flow when handling errors.
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 })
}
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;
}