Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // master code
  2. const cp = require("child_process");
  3. const testProcess = cp.fork("../fileToRun");
  4.  
  5. let timeout = [];
  6.  
  7. testProcess.on("message", (m) =>{
  8.   console.log("Message from child:", m)
  9.  
  10.   if(timeout.length){
  11.     timeout.forEach(timer =>{
  12.       clearTimeout(timer)
  13.     })
  14.     timeout = [];
  15.   }
  16. });
  17.  
  18.  
  19. function sendToWorker(){
  20.     testProcess.send({"pay":"load"});
  21.     timeout.push(setTimeout(()=>process.exit(1), 15000))  
  22. }
  23.  
  24. //worker code
  25.  
  26. process.on("message", (msgFromParent) =>{
  27.     process.send("Message recieved");
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement