apache / apache/cordova

Use async functions wherever applicable

Open
#175 0 comments 2 reactions 0 assignees View on GitHub
enhancement hacktoberfest
Dominant language
No language data
Stars
710
Forks
75
PR merge metrics
No merged PRs in 30d

Description

Using the `async` keyword ensures that a function will **always** return a Promise. Previously this was achieved by wrapping the function body in `return Promise.resolve().then(…)` which has a very slight async penalty and can make stack traces harder to read.

### Definition of done
For all known asynchronous functions:
- add `async` keyword
- undo wrapping in `Promise.resolve().then(…)` if applicable
- undo any explicit result wrapping
`return Promise.resolve(…)` ⮕ `return …`
- throw errors instead of returning rejections
`return Promise.reject(new Error(…))` ⮕ `throw new Error(…)`
- _optional:_ use `await` & `try/catch` in the function body instead of traditional promise handling

## Task list

### Tools/libs
- [ ] cordova-cli
- [ ] cordova-lib
- [ ] cordova-create
- [ ] cordova-fetch (src-only: https://github.com/apache/cordova-fetch/pull/89)
- [ ] cordova-common
- [ ] cordova-serve
- [ ] cordova-js (only the Node.js part)

### Platforms (only the Node.js part)
- [ ] cordova-android
- [ ] cordova-browser
- [ ] cordova-ios
- [ ] cordova-windows

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.