Created
August 2, 2019 01:52
-
-
Save 0xCourtney/81763b9a0aa0e8fb6aa099adf55369b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var returnedArray = []; | |
if (cluster.isMaster) { | |
console.log(`Master ${process.pid} is running`); | |
// Fork workers | |
for (let i = 0; i < numCPUs; i++) { | |
const worker = cluster.fork(); | |
} | |
} else { | |
app.post('/api/multiThread', (req, res) => { | |
let { turfs } = req.body | |
const startTime = Date.now() | |
const promisedTurfs = turfs.map(turf => { | |
return convertAddressToCoordinates(turf.address) | |
.then(coordinates => { | |
turf.lat = coordinates[0].latitude | |
turf.lng = coordinates[0].longitude | |
return turf | |
}).catch(err => console.error(err)) | |
}) | |
Promise.all(promisedTurfs).then((results) => { | |
const turfs = results.map((result) => { | |
return result | |
}) | |
console.log(`PID - ${process.pid} / Elapsed Time: ${Date.now() - startTime}`) | |
res.send(turfs).status(200) | |
}) | |
}); | |
app.listen(PORT, () => { | |
console.log(`Gettin schwiffty on port ${PORT}`); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment