Created
August 10, 2020 21:55
-
-
Save mmarchini/48f005fffffcbfe24c821a22b146c614 to your computer and use it in GitHub Desktop.
resource-leak-mitigation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const server = http.createServer(handle); | |
server.listen(3000); | |
process.on('unhandledRejection', (err) => { | |
throw err; | |
}); | |
function handle (req, res) { | |
doStuff() | |
.then((body) => { | |
res.end(body); | |
}); | |
} | |
function doStuff () { | |
if (Math.random() < 0.5) { | |
return Promise.reject(new Error('kaboom')); | |
} | |
return Promise.resolve('hello world'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment