Skip to content

Added promises to "recipes" documentation #1220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from Mar 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/RECIPES.md
Original file line number Diff line number Diff line change
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>`.