Is there possible to make async call/thread to not hang editor on heavy code?


#1

Hello,

Trying to use in my package “tokenizeLines” from API, but on heavy files it froze editor for a few seconds, i’m tested on file some like 12-14K lines. So is it possible to execute that function in async call or separate thread or any other way outside of main loop? Function is anyway used to gather data and then to parse it, so it not require immediate response to present something to user and can be executed fully in background.

Thank you,
Zetd


#2

It is quite easy to put code in a separate process. Read up on node’s child_process module.


#3

Yup, i’m thought about it, problem is environment, i can spawn node child process and pass the file path to access, but “tokenizeLines” is part of atom API, is there way to spawn child process with that environment or somehow to pass env?


#4

I doubt it. You can only run vanilla node in a child process.


#5

Oh, okay, thanks for answers. I’ll go for now with “displayBuffer.tokenizedBuffer” it private API but at least it not hang editor.