Reading a file blocks UI



I want to read and parse a text file inside a window process. I use readline and fs.createReadStream for that. I parse it line by line, and I want to show the progress of this operation. While console logs appear gradually, the window UI is completely blocked until it finishes processing.

Can you recommend some workaround for this issue? Maybe web workers? Or should I put the whole processing into the main process and make it talk to my window somehow?

UPDATE: It seems like web workers don’t inherit require method, so I can’t use Node’s modules, such as fs and readline.


Ok, here is what I did.

  1. In my window I send a path to a file through IPC and wait for asynchronous-reply.
  2. In the main process I create a fork and pass there a path.
  3. Inside the fork I parse a file line by line using mentioned above readline and fs.createReadStream. During this I send results gradually back to the main process through process.send, which in turn sends it back to the window.

What I’ve achieved by this: my UI freezes at first, than updates at 20% (approx), then freezes again until file is parsed. Now I’m confused. Why does one child process affect another child process? Does anybody know how to solve this?


How exactly are you waiting for an asynchronous reply in step #1? Generally, any time you say “waiting” that means blocking.


I simply subscribe on asynchronous-reply ipc.on('asynchronous-reply', myFunction)
MyFunction receives results, I see its output in the console, while the UI is blocked.
Is there another way?


I have no idea, really. I’m just guessing based on what you’ve said in your topic here.


Did You find the solution to this problem ?