[libgee/wip/issue/34] Flatten call structure a bit



commit 2b646cc0a3ec9b84555ded92a7bd2bc053ac3890
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Nov 25 18:15:36 2019 +0100

    Flatten call structure a bit

 gee/lazy.vala    | 12 ++++++++----
 gee/promise.vala | 26 +++++++++++++-------------
 2 files changed, 21 insertions(+), 17 deletions(-)
---
diff --git a/gee/lazy.vala b/gee/lazy.vala
index 4e09e8b..19839c5 100644
--- a/gee/lazy.vala
+++ b/gee/lazy.vala
@@ -110,14 +110,18 @@ public class Gee.Lazy<G> {
                        _mutex.lock ();
                        if (_lazy._func != null) {
                                if (_state == State.EVAL) {
+                                       bool res = true;
                                        while (_state == State.EVAL) {
-                                               if (!_eval.wait_until (_mutex, end_time)) {
-                                                       value = null;
-                                                       _mutex.unlock ();
-                                                       return false;
+                                               res = _eval.wait_until (_mutex, end_time);
+                                               if (!res) {
+                                                       break;
                                                }
                                        }
                                        _mutex.unlock ();
+                                       if (!res) {
+                                               value = null;
+                                               return false;
+                                       }
                                } else {
                                        do_eval ();
                                }
diff --git a/gee/promise.vala b/gee/promise.vala
index 020138e..ed7b872 100644
--- a/gee/promise.vala
+++ b/gee/promise.vala
@@ -92,11 +92,9 @@ public class Gee.Promise<G> {
                public unowned G wait () throws FutureError {
                        _mutex.lock ();
                        State state = _state;
-                       if (_state == State.INIT) {
-                               while (_state == State.INIT) {
-                                       _set.wait (_mutex);
-                                       state = _state;
-                               }
+                       while (_state == State.INIT) {
+                               _set.wait (_mutex);
+                               state = _state;
                        }
                        _mutex.unlock ();
                        switch (state) {
@@ -114,17 +112,19 @@ public class Gee.Promise<G> {
                public bool wait_until (int64 end_time, out unowned G? value = null) throws FutureError {
                        _mutex.lock ();
                        State state = _state;
-                       if (state == State.INIT) {
-                               while (_state == State.INIT) {
-                                       if (!_set.wait_until (_mutex, end_time)) {
-                                               value = null;
-                                               _mutex.unlock ();
-                                               return false;
-                                       }
-                                       state = _state;
+                       bool res = true;
+                       while (_state == State.INIT) {
+                               res = _set.wait_until (_mutex, end_time);
+                               if (!res) {
+                                       break;
                                }
+                               state = _state;
                        }
                        _mutex.unlock ();
+                       if (!res) {
+                               value = null;
+                               return false;
+                       }
                        switch (state) {
                        case State.ABANDON:
                                throw new FutureError.ABANDON_PROMISE ("Promise has been abandon");


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