On Thu, Apr 27, 2017, 05:03 Géza Búza <bgh...@gmail.com> wrote:

> Hi Philip,
>
> Thanks for the quick response.
>
> So it's single threaded, what a pity. The long running operation is IO and
> I already refactored my code to use async functions of GIO. I used
> *Promise* objects to handle the IO operations from JavaScript. The
> problem is that I need to wait for all IO calls to be completed before I
> can process the output and I done it with *Promise.all()* which waits for
> all Promises to be fulfilled. But that makes the code synchronous again. I
> could chain the IO calls, but that would require more refactoring.
>
> Regards,
> Geza
>

Hi Geza,

Promise.all should not make the code synchronous. I wonder if you are maybe
using the synchronous Gio APIs inside your Promise wrapping code.

Check wrapPromise() in the top half of [1] for an example.

Regards,
Philip C

[1] https://gist.github.com/ptomato/4973bb71c153c9109774b2392e8d22c3

>
> <philip.chime...@gmail.com> ezt írta (időpont: 2017. ápr. 27., Cs, 2:41):
>
>>
>>
>> On Wed, Apr 26, 2017, 15:08 Géza Búza <bgh...@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 <https://developer.gnome.org/gio/unstable/GTask.html> 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
>>
>>> --
> Üdvözlettel,
> Búza Géza
>
_______________________________________________
gnome-shell-list mailing list
gnome-shell-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gnome-shell-list

Reply via email to