[libgee] Fix and improve the implementation of Future.map



commit fc3f01d82229c7c19fc663886ca8a55e102de870
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sun Jul 7 11:46:48 2013 +0200

    Fix and improve the implementation of Future.map

 gee/mapfuture.vala |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)
---
diff --git a/gee/mapfuture.vala b/gee/mapfuture.vala
index bbafa54..1bc13a4 100644
--- a/gee/mapfuture.vala
+++ b/gee/mapfuture.vala
@@ -70,6 +70,10 @@ internal class Gee.MapFuture<A, G> : Object, Future<A> {
                _mutex.lock ();
                switch (_progress) {
                case Progress.INIT:
+                       if (!_base.wait_until (end_time)) {
+                               _mutex.unlock ();
+                               return false;
+                       }
                        value = go_map ();
                        ret_value = true;
                        break;
@@ -92,6 +96,30 @@ internal class Gee.MapFuture<A, G> : Object, Future<A> {
                return ret_value;
        }
 
+       public async unowned A wait_async () {
+               unowned G g = yield _base.wait_async ();
+               _mutex.lock ();
+               switch (_progress) {
+               case Progress.INIT:
+                       go_map ();
+                       return _value;
+               case Progress.PROGRESS:
+                       unowned A result = null;
+                       _when_done += Future.WhenDoneArrayElement<G>((res) => {
+                               result = res;
+                               wait_async.callback ();
+                       });
+                       _mutex.unlock ();
+                       yield;
+                       return _value;
+               case Progress.READY:
+                       _mutex.unlock ();
+                       return _value;
+               default:
+                       assert_not_reached ();
+               }
+       }
+
        public void when_done (Future.WhenDoneFunc<A> func) {
                _mutex.lock ();
                if (_progress == Progress.READY) {
@@ -103,7 +131,7 @@ internal class Gee.MapFuture<A, G> : Object, Future<A> {
                }
        }
 
-       private unowned A go_map () {
+       private inline unowned A go_map () {
                _progress = Progress.PROGRESS;
                _mutex.unlock ();
 


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