[gnome-boxes/gnome-3-4] Add Util.run_in_thread



commit d87f5d300705c98c068ab53391a3f93fbed2614a
Author: Alexander Larsson <alexl redhat com>
Date:   Tue May 8 09:37:33 2012 +0200

    Add Util.run_in_thread
    
    This lets us easily run sync methods async
    
    https://bugzilla.gnome.org/show_bug.cgi?id=675663

 src/util.vala |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/src/util.vala b/src/util.vala
index d64b704..7b2cfc3 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -435,4 +435,24 @@ namespace Boxes {
         debug ("check_module_kvm_loaded: " + yes_no (result));
         return result;
     }
+
+    public delegate void RunInThreadFunc () throws  GLib.Error;
+    public async void run_in_thread (RunInThreadFunc func) throws GLib.Error {
+        GLib.Error e = null;
+        GLib.g_io_scheduler_push_job ( (job, cancellable) => {
+                try {
+                    func ();
+                } catch (GLib.Error err) {
+                    e = err;
+                }
+                job.send_to_mainloop (() => {
+                        run_in_thread.callback ();
+                        return false;
+                    });
+                return false;
+            });
+        yield;
+        if (e != null)
+            throw e;
+    }
 }



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