[gitg/wip/commit: 8/28] Added async thread convenience class



commit d67a4820ff7c0a52e0bcf13b2cb5fefc74743e01
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sat Jun 29 19:28:25 2013 +0200

    Added async thread convenience class

 libgitg/Makefile.am     |    1 +
 libgitg/gitg-async.vala |   50 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/libgitg/Makefile.am b/libgitg/Makefile.am
index a61e484..305a9a1 100644
--- a/libgitg/Makefile.am
+++ b/libgitg/Makefile.am
@@ -41,6 +41,7 @@ libgitg.h: libgitg-1.0.la
 
 VALA_FILES =                                   \
        gitg-assembly-info.vala                 \
+       gitg-async.vala                         \
        gitg-branch.vala                        \
        gitg-branch-base.vala                   \
        gitg-repository.vala                    \
diff --git a/libgitg/gitg-async.vala b/libgitg/gitg-async.vala
new file mode 100644
index 0000000..3e0c178
--- /dev/null
+++ b/libgitg/gitg-async.vala
@@ -0,0 +1,50 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2013 - Jesse van den Kieboom
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gitg
+{
+
+internal class Async
+{
+       public delegate void ThreadFunc();
+
+       public static async void thread(ThreadFunc func)
+       {
+               SourceFunc callback = thread.callback;
+
+               try
+               {
+                       var t = new Thread<void *>.try("gitg-status-enumerator", () => {
+                               func();
+                               Idle.add((owned)callback);
+
+                               return null;
+                       });
+
+                       yield;
+
+                       t.join();
+               }
+               catch {}
+       }
+}
+
+}
+
+// ex:set ts=4 noet


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