ready.js 769 B

123456789101112131415161718192021222324
  1. "use strict";
  2. /** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
  3. /** @typedef {import("../index.js").ServerResponse} ServerResponse */
  4. /** @typedef {import("../index.js").Callback} Callback */
  5. /**
  6. * @template {IncomingMessage} Request
  7. * @template {ServerResponse} Response
  8. * @param {import("../index.js").FilledContext<Request, Response>} context context
  9. * @param {Callback} callback callback
  10. * @param {Request=} req req
  11. * @returns {void}
  12. */
  13. function ready(context, callback, req) {
  14. if (context.state) {
  15. callback(context.stats);
  16. return;
  17. }
  18. const name = req && req.url || callback.name;
  19. context.logger.info(`wait until bundle finished${name ? `: ${name}` : ""}`);
  20. context.callbacks.push(callback);
  21. }
  22. module.exports = ready;