Files
JiboOs/docs/utils/decorators.js
2026-03-16 13:53:01 +02:00

35 lines
1.4 KiB
JavaScript

/** @isInitialized method decorator
*
* Enforces that `this.isInitialized` is true or calls the callback with an error.
* Assumes the last argument is the callback. Must appear after @promisfy decorator, if any.
* @internal
*/
/** @promisify method decorator
*
* Assumes the last argument is suppose to be a callback. If the last
* argument isn't a function, then assume the callback was left off on
* purpose and wrap the method call in a promise and return the
* promise.
*
* Note: only works with callbacks that return one result (or less) in
* addition to the err argument. e.g. callback(err), or callback(err, res),
* but not callback(err, res, res2) (because of the way promises work)
* @internal
*/
/** @promisify_n method decorator
* Takes one argument, the argument number of the callback. If that
* argument isn't a function, then assume the callback was left off on
* purpose and wrap the method call in a promise and return the
* promise. The argument number is one-based: the first argument
* number is 1 (not zero), the second argument is 2, etc.
*
* The decorator takes the argument just like a function:
* @promisify_n(2) // if the second argument is the callback
*
* Note: only works with callbacks that return one result (or less) in
* addition to the err argument. e.g. callback(err), or callback(err, res),
* but not callback(err, res, res2) (because of the way promises work)
* @internal
*/