Skip to content

Instantly share code, notes, and snippets.

@mrtnbroder
Created February 10, 2016 18:26
Show Gist options
  • Select an option

  • Save mrtnbroder/7fe72163c9e35f5500c6 to your computer and use it in GitHub Desktop.

Select an option

Save mrtnbroder/7fe72163c9e35f5500c6 to your computer and use it in GitHub Desktop.
// side effects
const http = require('http')
const hostname = '127.0.0.1'
const port = 1337
http.createServer(httpEffect.serverCallback)
.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`)
});
@bahmutov
Copy link
Copy Markdown

The http... listen binds to a socket, making it unavailable for anyone else. If you try to run the code second time, it will fail, because the global state (the socket 1337) has changed. Even if this code cleaned up after itself and released the socket back, it would still be impure, because the execution depends on the outside environment (HTTP stack, operating system), and not just on the inputs to the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment