Skip to content

Instantly share code, notes, and snippets.

@fachryansyah
Created September 26, 2020 11:44
Show Gist options
  • Save fachryansyah/3d8a0032830d356b8f5ba2d12cd261e9 to your computer and use it in GitHub Desktop.
Save fachryansyah/3d8a0032830d356b8f5ba2d12cd261e9 to your computer and use it in GitHub Desktop.
GroupedMultithread.js
const { fork } = require('child_process');
const data = [
{
email: "[email protected]",
password: '123'
},
{
email: "[email protected]",
password: '123'
},
{
email: "[email protected]",
password: '123'
},
{
email: "[email protected]",
password: '123'
},
{
email: "[email protected]",
password: '123'
},
{
email: "[email protected]",
password: '123'
},
{
email: "[email protected]",
password: '123'
},
{
email: "[email protected]",
password: '123'
},
{
email: "[email protected]",
password: '123'
},
{
email: "[email protected]",
password: '123'
}
];
const parseMultiThreadData = (data, thread) => {
let groupedProccess = [];
const numOfProcess = data.length / thread;
let a = thread;
for (let i = 0; i < numOfProcess; i++) {
console.log(`===[ Proses ke ${i + 1} ]===`);
console.log(data.slice(i * thread, a));
groupedProccess.push(data.slice(i * thread, a));
a += thread;
}
// return groupedProccess;
}
// const startMultiThread = (parsedData) => {
// parsedData.forEach(data => {
// data.forEach(item => {
// const process = fork('./automation.js');
// process.send(item);
// process.on('message', (message) => {
// console.info(message);
// });
// })
// })
// }
parseMultiThreadData(data, 4);
// (async () => {
// const parsedData = await parseMultiThreadData(data, 4);
// await startMultiThread(parsedData)
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment