# All files / lib/tasks end-as-promise.js

100% Statements 19/19
100% Branches 5/5
100% Functions 1/1
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    192x
    2x
    2x
    2x
    2x
    2x
    216x
    216x
    216x
    216x
    216x
    216x
    21x
    21x
    216x
    216x
    216x
    216x
    216ximport Transaction from "../transaction";

    // End flow, this terminates the transaction and returns a Promise that
    // resolves when completed. If you want to make diffHTML return streams or
    // callbacks replace this function.
    export default function endAsPromise(/** @type {Transaction} */ transaction) {
      const { promises } = transaction;

      // Operate synchronously unless opted into a Promise-chain. Doesn't matter
      // if they are actually Promises or not, since they will all resolve
      // eventually with `Promise.all`.
      if (promises && promises.length) {
        return transaction.promise = Promise.all(promises).then(() => transaction.end());
      }

      // Pass off the remaining middleware to allow users to dive into the
      // transaction completed lifecycle event.
      return transaction.promise = Promise.resolve(transaction.end());
    }