index.js 1.2 KB

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ApolloServerPluginDrainHttpServer = void 0;
  4. const node_abort_controller_1 = require("node-abort-controller");
  5. const stoppable_js_1 = require("./stoppable.js");
  6. function ApolloServerPluginDrainHttpServer(options) {
  7. const stopper = new stoppable_js_1.Stopper(options.httpServer);
  8. return {
  9. async serverWillStart() {
  10. return {
  11. async drainServer() {
  12. const hardDestroyAbortController = new node_abort_controller_1.AbortController();
  13. const stopGracePeriodMillis = options.stopGracePeriodMillis ?? 10000;
  14. let timeout;
  15. if (stopGracePeriodMillis < Infinity) {
  16. timeout = setTimeout(() => hardDestroyAbortController.abort(), stopGracePeriodMillis);
  17. }
  18. await stopper.stop(hardDestroyAbortController.signal);
  19. if (timeout) {
  20. clearTimeout(timeout);
  21. }
  22. },
  23. };
  24. },
  25. };
  26. }
  27. exports.ApolloServerPluginDrainHttpServer = ApolloServerPluginDrainHttpServer;
  28. //# sourceMappingURL=index.js.map