ready.js 700 B

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