Skip to content

Commit

Permalink
docs: add examples to prefer-await-to-then (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMurphy authored and macklinu committed Apr 19, 2018
1 parent 1e95bab commit 5956eca
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/rules/prefer-await-to-then.md
@@ -1 +1,36 @@
# Prefer `await` to `then()` for reading Promise values (prefer-await-to-then)

#### Valid

```js
async function example() {
let val = await myPromise()
val = doSomethingSync(val)
return doSomethingElseAsync(val)
}

async function exampleTwo() {
try {
let val = await myPromise()
val = doSomethingSync(val)
return await doSomethingElseAsync(val)
} catch (err) {
errors(err)
}
}
```

#### Invalid

```js
function example() {
return myPromise.then(doSomethingSync).then(doSomethingElseAsync)
}

function exampleTwo() {
return myPromise
.then(doSomethingSync)
.then(doSomethingElseAsync)
.catch(errors)
}
```

0 comments on commit 5956eca

Please sign in to comment.