Re: Run a callback by GTask from an extension
- From: philip chimento gmail com
- To: Géza Búza <bghome gmail com>, gnome-shell-list gnome org
- Subject: Re: Run a callback by GTask from an extension
- Date: Thu, 27 Apr 2017 00:41:26 +0000
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]