diff --git a/lib/executor.js b/lib/executor.js index 6f0cf34..61275be 100755 --- a/lib/executor.js +++ b/lib/executor.js @@ -1,15 +1,41 @@ /** * Responsible for sequentially executing actions on the database + * @private */ class Waterfall { constructor () { + /** + * This is the internal Promise object which resolves when all the tasks of the `Waterfall` are done. + * + * It will change any time `this.waterfall` is called, this is why there is a getter `this.guardian` which retrieves + * the latest version of the guardian. + * @type {Promise} + * @private + */ this._guardian = Promise.resolve() } + /** + * Returns a Promise which resolves when all tasks up to when this function is called are done. + * + * This Promise cannot reject. + * @return {Promise} + */ get guardian () { return this._guardian } + /** + * @callback Waterfall~function + * @param {...[*]} args + * @return {Promise<*>} + */ + + /** + * + * @param {Waterfall~function} func + * @return {Waterfall~function} + */ waterfall (func) { return (...args) => { this._guardian = this.guardian.then(() => {