Spaces:
Sleeping
Sleeping
File size: 624 Bytes
1cc048f 0843ae5 1cc048f b7c2741 3ec92a5 b7c2741 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
const express = require('express');
const app = express();
const { Worker } = require('worker_threads')
app.get('/', (req, res) => {
res.send('Hello Express app!')
});
app.listen(7860, () => {
console.log('server started');
});
function runService(workerData) {
return new Promise((resolve, reject) => {
const worker = new Worker('./index.js', { workerData });
worker.on('message', resolve);
worker.on('error', reject);
worker.on('exit', (code) => {
if (code !== 0)
reject(new Error(`Worker stopped with exit code ${code}`));
})
})
}
for(var i = 0;i < 8;i++){
runService(1)
}
|