Skip to content

Commit 7008123

Browse files
Harrytmcw
authored andcommitted
docsL Added promises to "recipes" documentation (documentationjs#1220)
* Added promises to recipes docs * Syntax correction
1 parent 13abb9e commit 7008123

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/RECIPES.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,25 @@ The first documentation describes how you can call getTheTime without
174174
any arguments, and the second describes how you can call getTheTime with
175175
an argument. `documentation` will output two documented functions when you
176176
use this style.
177+
178+
## Promises
179+
180+
Promises have become a widely used feature in modern JavaScript. They are
181+
documented in a similar manner to arrays:
182+
183+
```js
184+
/**
185+
* Find a person's phone number in the database
186+
* @param {string} name person's name
187+
* @returns {Promise<string>} promise with the phone number
188+
*/
189+
function findPersonAge(name) {
190+
return new Promise((resolve, reject) => {
191+
db.find({ name: name })
192+
.then(object => resolve(object.age))
193+
.catch(err => reject(err))
194+
})
195+
}
196+
```
197+
198+
Multiple parameters within the `resolve` can be documented like so: `Promise<string, number>`.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy