Skip to content

Commit

Permalink
docsL Added promises to "recipes" documentation (#1220)
Browse files Browse the repository at this point in the history
* Added promises to recipes docs

* Syntax correction
  • Loading branch information
Harry authored and tmcw committed Mar 16, 2019
1 parent 13abb9e commit 7008123
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/RECIPES.md
Expand Up @@ -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} name person's name
* @returns {Promise<string>} 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<string, number>`.

0 comments on commit 7008123

Please sign in to comment.