|
|
@ -1,15 +1,41 @@ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Responsible for sequentially executing actions on the database |
|
|
|
* Responsible for sequentially executing actions on the database |
|
|
|
|
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class Waterfall { |
|
|
|
class Waterfall { |
|
|
|
constructor () { |
|
|
|
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<void>} |
|
|
|
|
|
|
|
* @private |
|
|
|
|
|
|
|
*/ |
|
|
|
this._guardian = Promise.resolve() |
|
|
|
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<void>} |
|
|
|
|
|
|
|
*/ |
|
|
|
get guardian () { |
|
|
|
get guardian () { |
|
|
|
return this._guardian |
|
|
|
return this._guardian |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @callback Waterfall~function |
|
|
|
|
|
|
|
* @param {...[*]} args |
|
|
|
|
|
|
|
* @return {Promise<*>} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {Waterfall~function} func |
|
|
|
|
|
|
|
* @return {Waterfall~function} |
|
|
|
|
|
|
|
*/ |
|
|
|
waterfall (func) { |
|
|
|
waterfall (func) { |
|
|
|
return (...args) => { |
|
|
|
return (...args) => { |
|
|
|
this._guardian = this.guardian.then(() => { |
|
|
|
this._guardian = this.guardian.then(() => { |
|
|
|