ampproject / ampproject/amphtml

I2I: Convert Promise chains to async/await

Open
#29,216 9 comments 0 reactions 1 assignee Claimed by @rileyajones View on GitHub
INTENT TO IMPLEMENT P3: When Possible Stale WG: infra
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

From my manual perusal of different tests, as well as some of the issue threads linked in https://github.com/ampproject/amphtml/issues/14360, I see there are a lot of issues with functions that create promise chains with no `catch` handler, ensuring that failures will be unhandled rejections and making it impossible to catch them synchronously in test code. I suspect general confusion around how async functions, promises, and async errors work all combine to create a systemic issue where there's no consistent "contract" that a developer or test-writer can depend on when dealing with functions that use or produce promises.

I think a general cleanup effort to migrate from Promises toward async/await could clear up a lot of confusion and make some of these issues either go away or easier to diagnose. There are tools that can do this somewhat automatically (ex. [VS Code supports Promise->async](https://umaar.com/dev-tips/182-typescript-async-await/), and there are [tools](https://www.npmjs.com/package/@codemodsquad/asyncify) to do this at scale) and this is something that could be done in bulk, with small no-op PRs pushed out Rosie-style to individual files and their owners, distributing the workload across the team. This could occur in tandem with a Deep Dive providing clarity and best practices for the team.

Link for convenience: https://caniuse.com/#search=await

@rsimha WDYT?
@jridgewell Would shifting to async/await carry performance or compilation issues we should be concerned about, or does Babel do a decent job with this already?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.