You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.1 KiB

4 years ago
  1. killable
  2. ========
  3. Keeps track of a server's open sockets so they can be destroyed at a
  4. moment's notice. This way, the server connection can be killed very
  5. fast.
  6. Installation
  7. ------------
  8. ```
  9. npm install killable
  10. ```
  11. Example usage
  12. -------------
  13. Using express:
  14. ('server' in the example is just an ``http.server``, so other frameworks
  15. or pure Node should work just as well.)
  16. ```javascript
  17. var killable = require('killable');
  18. var app = require('express')();
  19. var server;
  20. app.route('/', function (req, res, next) {
  21. res.send('Server is going down NOW!');
  22. server.kill(function () {
  23. //the server is down when this is called. That won't take long.
  24. });
  25. });
  26. var server = app.listen(8080);
  27. killable(server);
  28. ```
  29. API
  30. ---
  31. The ``killable`` module is callable. When you call it on a Node
  32. ``http.Server`` object, it will add a ``server.kill()`` method on it. It
  33. returns the server object.
  34. ``server.kill([callback])`` closes all open sockets and calls
  35. ``server.close()``, to which the ``callback`` is passed on.
  36. Inspired by: http://stackoverflow.com/a/14636625
  37. License
  38. -------
  39. ISC