From e0b0897ead615b4c01d9ebf77ac86677dc31b67b Mon Sep 17 00:00:00 2001 From: Harry Stanton Date: Fri, 15 Mar 2019 13:29:03 +0000 Subject: [PATCH 1/2] Added promises to recipes docs --- docs/RECIPES.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/RECIPES.md b/docs/RECIPES.md index 5133e6f0f..150e8338d 100644 --- a/docs/RECIPES.md +++ b/docs/RECIPES.md @@ -174,3 +174,25 @@ The first documentation describes how you can call getTheTime without any arguments, and the second describes how you can call getTheTime with an argument. `documentation` will output two documented functions when you use this style. + +## Promises + +Promises have become a widely used feature in modern JavaScript. They are +documented in a similar manner to arrays: + +```js +/** + * Find a person's phone number in the database + * @param {string} person's name + * @returns {Promise} promise with the phone number + */ +function findPersonAge(name) { + return new Promise((resolve, reject) => { + db.find({ name: name }) + .then(object => resolve(object.age)) + .catch(err => reject(err)) + }) +} +``` + +Multiple parameters within the `resolve` can be documented like so: `Promise`. From de40e7940443ed250f552dd79f803b5255e99ad1 Mon Sep 17 00:00:00 2001 From: Harry Stanton Date: Fri, 15 Mar 2019 13:50:52 +0000 Subject: [PATCH 2/2] Syntax correction --- docs/RECIPES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/RECIPES.md b/docs/RECIPES.md index 150e8338d..7d96eb3c8 100644 --- a/docs/RECIPES.md +++ b/docs/RECIPES.md @@ -183,7 +183,7 @@ documented in a similar manner to arrays: ```js /** * Find a person's phone number in the database - * @param {string} person's name + * @param {string} name person's name * @returns {Promise} promise with the phone number */ function findPersonAge(name) {