[gnome-weather/ewlsh/march-fixes-prerelease: 1/2] Ensure running mainloop does not block pending promises




commit c34225fa42d9b06effcc3d726c202450677bb916
Author: Evan Welsh <contact evanwelsh com>
Date:   Fri Mar 4 22:59:52 2022 -0800

    Ensure running mainloop does not block pending promises
    
    This avoids GNOME/gjs#468 until a better helper API exists.

 src/app/main.js     | 13 ++++++++++++-
 src/service/main.js | 12 +++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/src/app/main.js b/src/app/main.js
index 52adc9b..b6197eb 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -38,4 +38,15 @@ globalThis.getApp = function () {
     return Gio.Application.get_default();
 };
 
-new WeatherApplication().run([system.programInvocationName, ...system.programArgs]);
+let application = new WeatherApplication();
+
+setTimeout(() => {
+    imports.mainloop.quit();
+
+    const code = application.run([system.programInvocationName, ...system.programArgs]);
+    application = null;
+
+    system.exit(code);
+});
+
+imports.mainloop.run();
\ No newline at end of file
diff --git a/src/service/main.js b/src/service/main.js
index b0ace5e..dfddeef 100644
--- a/src/service/main.js
+++ b/src/service/main.js
@@ -23,6 +23,8 @@ pkg.require({ 'Gio': '2.0',
               'GObject': '2.0',
               'GWeather': '4.0' });
 
+import * as system from 'system';
+
 import Gio from 'gi://Gio';
 import GLib from 'gi://GLib';
 import GObject from 'gi://GObject';
@@ -108,5 +110,13 @@ const BackgroundService = GObject.registerClass(
 export function main(argv) {
     initEnvironment();
 
-    return (new BackgroundService()).run(argv);
+    setTimeout(() => {
+        imports.mainloop.quit();
+
+        const code = (new BackgroundService()).run(argv);
+
+        system.exit(code);
+    });
+
+    imports.mainloop.run();
 }


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