Skip to content

Commit

Permalink
Add JSDoc documentation for generic helper function callCallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
lindapaiste committed Feb 25, 2022
1 parent 792add4 commit 552d16d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/utils/callcallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT


/**
* Most ml5 methods accept a callback function which will be
* called with the arguments (error, result).
*
* Generic type T describes the type of the result.
* @template T
* @callback ML5Callback<T>
* @param {unknown} error - any error thrown during the execution of the function.
* @param {T} [result] - the expected result, if successful.
* @return {void} - callbacks can have side effects, but should not return a value.
*/

/**
* Generic type T describes the type of the result, ie. the value that the Promise will resolve to.
* @template T
* @param {Promise<T>} promise - the Promise to resolve.
* @param {ML5Callback<T>} [callback] - optional callback function to be called
* with the result or error from the resolved Promise.
* @return {Promise<T>} - returns the underlying Promise, which may be rejected.
*/
export default function callCallback(promise, callback) {
if (!callback) return promise;
return new Promise((resolve, reject) => {
Expand Down

0 comments on commit 552d16d

Please sign in to comment.