Skip to content

add returning promise example for returns tag #175

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 1 commit into from
Aug 3, 2017
Merged
Show file tree
Hide file tree
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
37 changes: 27 additions & 10 deletions content/en/tags-returns.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ tag.
```js
/**
* Returns the sum of a and b
* @param {Number} a
* @param {Number} b
* @returns {Number}
* @param {number} a
* @param {number} b
* @returns {number}
*/
function sum(a, b) {
return a + b;
Expand All @@ -45,9 +45,9 @@ function sum(a, b) {
```js
/**
* Returns the sum of a and b
* @param {Number} a
* @param {Number} b
* @returns {Number} Sum of a and b
* @param {number} a
* @param {number} b
* @returns {number} Sum of a and b
*/
function sum(a, b) {
return a + b;
Expand All @@ -60,10 +60,10 @@ function sum(a, b) {
```js
/**
* Returns the sum of a and b
* @param {Number} a
* @param {Number} b
* @param {Boolean} retArr If set to true, the function will return an array
* @returns {(Number|Array)} Sum of a and b or an array that contains a, b and the sum of a and b.
* @param {number} a
* @param {number} b
* @param {boolean} retArr If set to true, the function will return an array
* @returns {(number|Array)} Sum of a and b or an array that contains a, b and the sum of a and b.
*/
function sum(a, b, retArr) {
if (retArr) {
Expand All @@ -73,3 +73,20 @@ function sum(a, b, retArr) {
}
```
{% endexample %}

{% example "Returns a promise" %}

```js
/**
* Returns the sum of a and b
* @param {number} a
* @param {number} b
* @returns {Promise<number>} Promise object represents the sum of a and b
*/
function sumAsync(a, b) {
return new Promise(function(resolve, reject) {
resolve(a + b);
});
}
```
{% endexample %}
48 changes: 28 additions & 20 deletions tags-returns.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ <h2 id="synonyms">Synonyms</h2>
<code>@return</code>
</p>
<h2 id="syntax">Syntax</h2>
<p><code>@returns [{type}] [description]</code>
</p>
<p><code>@returns [{type}] [description]</code></p>
<h2 id="overview">Overview</h2>
<p>The <code>@returns</code> tag documents the value that a function returns.</p>
<p>If you are documenting a generator function, use the <a href="tags-yields.html"><code>@yields</code> tag</a> instead of this tag.
Expand All @@ -55,43 +54,53 @@ <h2 id="examples">Examples</h2>
<figure>
<figcaption>Return value with a type</figcaption><pre class="prettyprint lang-js"><code>/**
* Returns the sum of a and b
* @param {Number} a
* @param {Number} b
* @returns {Number}
* @param {number} a
* @param {number} b
* @returns {number}
*/
function sum(a, b) {
return a + b;
}
</code></pre>
</figure>
</code></pre></figure>
<figure>
<figcaption>Return value with a type and description</figcaption><pre class="prettyprint lang-js"><code>/**
* Returns the sum of a and b
* @param {Number} a
* @param {Number} b
* @returns {Number} Sum of a and b
* @param {number} a
* @param {number} b
* @returns {number} Sum of a and b
*/
function sum(a, b) {
return a + b;
}
</code></pre>
</figure>
</code></pre></figure>
<figure>
<figcaption>Return value with multiple types</figcaption><pre class="prettyprint lang-js"><code>/**
* Returns the sum of a and b
* @param {Number} a
* @param {Number} b
* @param {Boolean} retArr If set to true, the function will return an array
* @returns {(Number|Array)} Sum of a and b or an array that contains a, b and the sum of a and b.
* @param {number} a
* @param {number} b
* @param {boolean} retArr If set to true, the function will return an array
* @returns {(number|Array)} Sum of a and b or an array that contains a, b and the sum of a and b.
*/
function sum(a, b, retArr) {
if (retArr) {
return [a, b, a + b];
}
return a + b;
}
</code></pre>
</figure>
</code></pre></figure>
<figure>
<figcaption>Returns a promise</figcaption><pre class="prettyprint lang-js"><code>/**
* Returns the sum of a and b
* @param {number} a
* @param {number} b
* @returns {Promise<number>} Promise object represents the sum of a and b
*/
function sumAsync(a, b) {
return new Promise(function(resolve, reject) {
resolve(a + b);
});
}
</code></pre></figure>
<h2 id="related-links">Related Links</h2>
<ul>
<li>
Expand All @@ -104,8 +113,7 @@ <h2 id="related-links">Related Links</h2>
</article>
<footer>
<a class="license-badge" href="http://creativecommons.org/licenses/by-sa/3.0/">
<img alt="Creative Commons License" class="license-badge" src="images/cc-by-sa.svg" width="80" height="15" />
</a>
<img alt="Creative Commons License" class="license-badge" src="images/cc-by-sa.svg" width="80" height="15" /></a>
<br> Copyright &#169; 2011-2017 the
<a href="https://github.com/jsdoc3/jsdoc3.github.com/contributors">contributors</a> to the JSDoc 3 documentation project.
<br> This website is <a href="https://github.com/jsdoc3/jsdoc3.github.com">open source</a> and is licensed under the <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">
Expand Down