On Tue, Jan 12, 2016 at 10:44 PM, <philip.chime...@gmail.com> wrote:

> On Tue, Jan 12, 2016 at 10:23 PM Per <pmknut...@gmail.com> wrote:
>
>> Is there a way I can run a command asynchronously in Gnome JavaScript?
>>
>
> There is Gio.Subprocess, but it would be better to do all this without
> shelling out in the first place. It's not good to spawn hundreds of
> processes at once, synchronously or not! Here's some (untested) code that
> might help you:
>

​Thanks! I would never have figured this out. The code worked great as-is.
No more Gnome shell freezing while running the loop.​

This code still may have a problem; you'll want to avoid running hundreds
> of threads at the same time, all doing file I/O. To solve that, you could
> consider using recursion instead of a loop; start with an array of files
> that you want to process, pass it into a function with the above code, then
> in the callback to set_attributes_async(), pop the processed element off
> the array and do the same thing again until the array is empty. That way,
> the files will all be processed sequentially and asynchronously.
>

​Yes, this is a better solution. I'm testing on hundreds of I/O threads,
but the code may have to run thousands of these updates in edge cases. As
they're not time-sensitive, executing them sequentially and at low priority
seems to be preferred.

Thanks again for the excellent solution!​
_______________________________________________
javascript-list mailing list
javascript-list@gnome.org
https://mail.gnome.org/mailman/listinfo/javascript-list

Reply via email to