Skip to content

Commit 552d16d

Browse files
committed
Add JSDoc documentation for generic helper function callCallback.
1 parent 792add4 commit 552d16d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/utils/callcallback.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@
33
// This software is released under the MIT License.
44
// https://opensource.org/licenses/MIT
55

6+
7+
/**
8+
* Most ml5 methods accept a callback function which will be
9+
* called with the arguments (error, result).
10+
*
11+
* Generic type T describes the type of the result.
12+
* @template T
13+
* @callback ML5Callback<T>
14+
* @param {unknown} error - any error thrown during the execution of the function.
15+
* @param {T} [result] - the expected result, if successful.
16+
* @return {void} - callbacks can have side effects, but should not return a value.
17+
*/
18+
19+
/**
20+
* Generic type T describes the type of the result, ie. the value that the Promise will resolve to.
21+
* @template T
22+
* @param {Promise<T>} promise - the Promise to resolve.
23+
* @param {ML5Callback<T>} [callback] - optional callback function to be called
24+
* with the result or error from the resolved Promise.
25+
* @return {Promise<T>} - returns the underlying Promise, which may be rejected.
26+
*/
627
export default function callCallback(promise, callback) {
728
if (!callback) return promise;
829
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)