Ein Projekt das es ermöglicht Beerpong über das Internet von zwei unabhängigen positionen aus zu spielen. Entstehung im Rahmen einer Praktikumsaufgabe im Fach Interaktion.
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.

README.md 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # on-finished
  2. [![NPM Version](http://img.shields.io/npm/v/on-finished.svg?style=flat)](https://www.npmjs.org/package/on-finished)
  3. [![Node.js Version](http://img.shields.io/badge/node.js->=_0.8-brightgreen.svg?style=flat)](http://nodejs.org/download/)
  4. [![Build Status](http://img.shields.io/travis/jshttp/on-finished.svg?style=flat)](https://travis-ci.org/jshttp/on-finished)
  5. [![Coverage Status](https://img.shields.io/coveralls/jshttp/on-finished.svg?style=flat)](https://coveralls.io/r/jshttp/on-finished)
  6. Execute a callback when a request closes, finishes, or errors.
  7. ## Install
  8. ```sh
  9. $ npm install on-finished
  10. ```
  11. ## API
  12. ```js
  13. var onFinished = require('on-finished')
  14. ```
  15. ### onFinished(res, listener)
  16. Attach a listener to listen for the response to finish. The listener will
  17. be invoked only once when the response finished. If the response finished
  18. to to an error, the first argument will contain the error.
  19. Listening to the end of a response would be used to close things associated
  20. with the response, like open files.
  21. ```js
  22. onFinished(res, function (err) {
  23. // clean up open fds, etc.
  24. })
  25. ```
  26. ### onFinished(req, listener)
  27. Attach a listener to listen for the request to finish. The listener will
  28. be invoked only once when the request finished. If the request finished
  29. to to an error, the first argument will contain the error.
  30. Listening to the end of a request would be used to know when to continue
  31. after reading the data.
  32. ```js
  33. var data = ''
  34. req.setEncoding('utf8')
  35. res.on('data', function (str) {
  36. data += str
  37. })
  38. onFinished(req, function (err) {
  39. // data is read unless there is err
  40. })
  41. ```
  42. ### onFinished.isFinished(res)
  43. Determine if `res` is already finished. This would be useful to check and
  44. not even start certain operations if the response has already finished.
  45. ### onFinished.isFinished(req)
  46. Determine if `req` is already finished. This would be useful to check and
  47. not even start certain operations if the request has already finished.
  48. ### Example
  49. The following code ensures that file descriptors are always closed
  50. once the response finishes.
  51. ```js
  52. var destroy = require('destroy')
  53. var http = require('http')
  54. var onFinished = require('finished')
  55. http.createServer(function onRequest(req, res) {
  56. var stream = fs.createReadStream('package.json')
  57. stream.pipe(res)
  58. onFinished(res, function (err) {
  59. destroy(stream)
  60. })
  61. })
  62. ```
  63. ## License
  64. [MIT](LICENSE)