Last active
November 10, 2018 17:23
-
-
Save micheleriva/bdf7ba3e8a3fb109794ed2738077c5b9 to your computer and use it in GitHub Desktop.
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 cluster = require('cluster') | |
const { cpus } = require('os') | |
const numWorkers = cpus().length | |
const isMaster = cluster.isMaster | |
if (isMaster) { | |
process.stdout.write('I am master!') | |
const workers = [...Array(numWorkers)].map(_ => cluster.fork()) | |
} else { | |
process.stdout.write('I am a worker!') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment