pull/11/head
Timothée Rebours 3 years ago
parent a2528ee45e
commit 7709369e49
  1. 26
      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<void>}
* @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<void>}
*/
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(() => {

Loading…
Cancel
Save