From 9b187b331ebfb9408a4b4726d6312c5fec9d3b08 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Sun, 25 Mar 2018 09:49:32 -0700 Subject: [PATCH] docs: add examples to `prefer-await-to-then` --- docs/rules/prefer-await-to-then.md | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/rules/prefer-await-to-then.md b/docs/rules/prefer-await-to-then.md index 6ce3270b..4e40f2ea 100644 --- a/docs/rules/prefer-await-to-then.md +++ b/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) +} +```