Created
September 26, 2020 11:44
-
-
Save fachryansyah/3d8a0032830d356b8f5ba2d12cd261e9 to your computer and use it in GitHub Desktop.
GroupedMultithread.js
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
| 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