Hi Philip, Thanks for the example. I have similar code to load file contents, see the *read()* method here: https://github.com/elvetemedve/gnome-shell-extension-system-monitor/blob/master/System_Monitor%40bghome.gmail.com/helpers/file.js#L16-L31 I don't see the issue with it. The synchronous version is still there, but not used any more: https://github.com/elvetemedve/gnome-shell-extension-system-monitor/blob/master/System_Monitor%40bghome.gmail.com/file.js
I have read that the recently released Gnome started to support Promises, but so far I used a polifill https://github.com/elvetemedve/gnome-shell-extension-system-monitor/blob/master/System_Monitor%40bghome.gmail.com/helpers/promise.js Should I create a *MainLoop* object as it is shown in the example? I don't really get how that works? Regards, Geza <philip.chime...@gmail.com> ezt írta (időpont: 2017. ápr. 27., Cs, 17:20): > 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 >> > -- Ü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