Skip to content

Commit 7491db0

Browse files
zhengzongyihegemonic
authored andcommitted
add returning promise example for returns tag (#175)
1 parent 6e52272 commit 7491db0

File tree

2 files changed

+55
-30
lines changed

2 files changed

+55
-30
lines changed

content/en/tags-returns.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ tag.
3030
```js
3131
/**
3232
* Returns the sum of a and b
33-
* @param {Number} a
34-
* @param {Number} b
35-
* @returns {Number}
33+
* @param {number} a
34+
* @param {number} b
35+
* @returns {number}
3636
*/
3737
function sum(a, b) {
3838
return a + b;
@@ -45,9 +45,9 @@ function sum(a, b) {
4545
```js
4646
/**
4747
* Returns the sum of a and b
48-
* @param {Number} a
49-
* @param {Number} b
50-
* @returns {Number} Sum of a and b
48+
* @param {number} a
49+
* @param {number} b
50+
* @returns {number} Sum of a and b
5151
*/
5252
function sum(a, b) {
5353
return a + b;
@@ -60,10 +60,10 @@ function sum(a, b) {
6060
```js
6161
/**
6262
* Returns the sum of a and b
63-
* @param {Number} a
64-
* @param {Number} b
65-
* @param {Boolean} retArr If set to true, the function will return an array
66-
* @returns {(Number|Array)} Sum of a and b or an array that contains a, b and the sum of a and b.
63+
* @param {number} a
64+
* @param {number} b
65+
* @param {boolean} retArr If set to true, the function will return an array
66+
* @returns {(number|Array)} Sum of a and b or an array that contains a, b and the sum of a and b.
6767
*/
6868
function sum(a, b, retArr) {
6969
if (retArr) {
@@ -73,3 +73,20 @@ function sum(a, b, retArr) {
7373
}
7474
```
7575
{% endexample %}
76+
77+
{% example "Returns a promise" %}
78+
79+
```js
80+
/**
81+
* Returns the sum of a and b
82+
* @param {number} a
83+
* @param {number} b
84+
* @returns {Promise<number>} Promise object represents the sum of a and b
85+
*/
86+
function sumAsync(a, b) {
87+
return new Promise(function(resolve, reject) {
88+
resolve(a + b);
89+
});
90+
}
91+
```
92+
{% endexample %}

tags-returns.html

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ <h2 id="synonyms">Synonyms</h2>
4545
<code>@return</code>
4646
</p>
4747
<h2 id="syntax">Syntax</h2>
48-
<p><code>@returns [{type}] [description]</code>
49-
</p>
48+
<p><code>@returns [{type}] [description]</code></p>
5049
<h2 id="overview">Overview</h2>
5150
<p>The <code>@returns</code> tag documents the value that a function returns.</p>
5251
<p>If you are documenting a generator function, use the <a href="tags-yields.html"><code>@yields</code> tag</a> instead of this tag.
@@ -55,43 +54,53 @@ <h2 id="examples">Examples</h2>
5554
<figure>
5655
<figcaption>Return value with a type</figcaption><pre class="prettyprint lang-js"><code>/**
5756
* Returns the sum of a and b
58-
* @param {Number} a
59-
* @param {Number} b
60-
* @returns {Number}
57+
* @param {number} a
58+
* @param {number} b
59+
* @returns {number}
6160
*/
6261
function sum(a, b) {
6362
return a + b;
6463
}
65-
</code></pre>
66-
</figure>
64+
</code></pre></figure>
6765
<figure>
6866
<figcaption>Return value with a type and description</figcaption><pre class="prettyprint lang-js"><code>/**
6967
* Returns the sum of a and b
70-
* @param {Number} a
71-
* @param {Number} b
72-
* @returns {Number} Sum of a and b
68+
* @param {number} a
69+
* @param {number} b
70+
* @returns {number} Sum of a and b
7371
*/
7472
function sum(a, b) {
7573
return a + b;
7674
}
77-
</code></pre>
78-
</figure>
75+
</code></pre></figure>
7976
<figure>
8077
<figcaption>Return value with multiple types</figcaption><pre class="prettyprint lang-js"><code>/**
8178
* Returns the sum of a and b
82-
* @param {Number} a
83-
* @param {Number} b
84-
* @param {Boolean} retArr If set to true, the function will return an array
85-
* @returns {(Number|Array)} Sum of a and b or an array that contains a, b and the sum of a and b.
79+
* @param {number} a
80+
* @param {number} b
81+
* @param {boolean} retArr If set to true, the function will return an array
82+
* @returns {(number|Array)} Sum of a and b or an array that contains a, b and the sum of a and b.
8683
*/
8784
function sum(a, b, retArr) {
8885
if (retArr) {
8986
return [a, b, a + b];
9087
}
9188
return a + b;
9289
}
93-
</code></pre>
94-
</figure>
90+
</code></pre></figure>
91+
<figure>
92+
<figcaption>Returns a promise</figcaption><pre class="prettyprint lang-js"><code>/**
93+
* Returns the sum of a and b
94+
* @param {number} a
95+
* @param {number} b
96+
* @returns {Promise<number>} Promise object represents the sum of a and b
97+
*/
98+
function sumAsync(a, b) {
99+
return new Promise(function(resolve, reject) {
100+
resolve(a + b);
101+
});
102+
}
103+
</code></pre></figure>
95104
<h2 id="related-links">Related Links</h2>
96105
<ul>
97106
<li>
@@ -104,8 +113,7 @@ <h2 id="related-links">Related Links</h2>
104113
</article>
105114
<footer>
106115
<a class="license-badge" href="http://creativecommons.org/licenses/by-sa/3.0/">
107-
<img alt="Creative Commons License" class="license-badge" src="images/cc-by-sa.svg" width="80" height="15" />
108-
</a>
116+
<img alt="Creative Commons License" class="license-badge" src="images/cc-by-sa.svg" width="80" height="15" /></a>
109117
<br> Copyright &#169; 2011-2017 the
110118
<a href="https://github.com/jsdoc3/jsdoc3.github.com/contributors">contributors</a> to the JSDoc 3 documentation project.
111119
<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/">

0 commit comments

Comments
 (0)