Re: Run a callback by GTask from an extension





On Wed, Apr 26, 2017, 15:08 Géza Búza <bghome gmail com> wrote:

Hi everybody,

I run into an issue while developing an extension for Gnome Shell.
Long running _javascript_ code can make the whole Gnome Shell unresponsive for a second. Since I cannot reduce the execution time of the long running code, I want to move it out of the main loop's thread to a new one to make the UI update independent. I found that the best way would be to create a GTask to run my synchronous JS code asynchronously.

Hi Geza,

GJS is single-threaded; you can't run JS code from a separate thread. GTask, as you have noticed, is not usable from GJS and this is one of the reasons why.

However, if your long-running operation is I/O, then you can simply use Gio's asynchronous operations and not worry about blocking the UI. Effectively Gio will decide whether to run the C code in a thread or not.

If it is a long-running calculation or something like that, then you will have to iterate the main loop yourself often enough during the calculation so that the UI doesn't block.

Regards,
Philip C



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]