From c95c3bf11f924880302ed62f090af43743396643 Mon Sep 17 00:00:00 2001 From: Zongyi Zheng Date: Fri, 28 Jul 2017 01:32:42 +0800 Subject: [PATCH] add returning promise example for `returns` tag --- content/en/tags-returns.md | 37 +++++++++++++++++++++-------- tags-returns.html | 48 ++++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/content/en/tags-returns.md b/content/en/tags-returns.md index 44d864b5..116d80d6 100644 --- a/content/en/tags-returns.md +++ b/content/en/tags-returns.md @@ -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; @@ -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; @@ -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) { @@ -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} Promise object represents the sum of a and b + */ +function sumAsync(a, b) { + return new Promise(function(resolve, reject) { + resolve(a + b); + }); +} +``` +{% endexample %} \ No newline at end of file diff --git a/tags-returns.html b/tags-returns.html index 7ccc018d..07b7ed93 100644 --- a/tags-returns.html +++ b/tags-returns.html @@ -45,8 +45,7 @@

Synonyms

@return

Syntax

-

@returns [{type}] [description] -

+

@returns [{type}] [description]

Overview

The @returns tag documents the value that a function returns.

If you are documenting a generator function, use the @yields tag instead of this tag. @@ -55,34 +54,32 @@

Examples

Return value with a type
/**
  * 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;
 }
-
-
+
Return value with a type and description
/**
  * 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;
 }
-
-
+
Return value with multiple types
/**
  * 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) {
@@ -90,8 +87,20 @@ 

Examples

} return a + b; } -
-
+ +
+
Returns a promise
/**
+ * Returns the sum of a and b
+ * @param {number} a
+ * @param {number} b
+ * @returns {Promise} Promise object represents the sum of a and b
+ */
+function sumAsync(a, b) {
+    return new Promise(function(resolve, reject) {
+        resolve(a + b);
+    });
+}
+