]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncMultiReadEntry.java
Fixed asynchronous recompute problems
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / AsyncMultiReadEntry.java
index 6f718f1fe4d2407cb92ee0cbd445e3dd2e1d3382..1791c50acccb37eb0fb41dbf4c3c149e0fc1c6d7 100644 (file)
@@ -14,6 +14,7 @@ package org.simantics.db.impl.query;
 import java.util.ArrayList;
 
 import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.common.GraphSemaphore;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.procedure.AsyncMultiProcedure;
@@ -88,23 +89,37 @@ final public class AsyncMultiReadEntry<T> extends CacheEntryBase<AsyncMultiProce
                        @Override
                        public void recompute(ReadGraphImpl graph) {
 
-                               request.perform(graph , new AsyncMultiProcedure<T>() {
+                               try {
 
-                                       @Override
-                                       public void execute(AsyncReadGraph graph, T result) {
-                                               addOrSet(result);
-                                       }
+                                       GraphSemaphore s = new GraphSemaphore(graph, 0);
 
-                                       public void finished(AsyncReadGraph graph) {
-                                               finish(graph);
-                                       };
+                                       request.perform(graph , new AsyncMultiProcedure<T>() {
 
-                                       @Override
-                                       public void exception(AsyncReadGraph graph, Throwable t) {
-                                               except(t);
-                                       }
+                                               @Override
+                                               public void execute(AsyncReadGraph graph, T result) {
+                                                       addOrSet(result);
+                                               }
 
-                               });
+                                               public void finished(AsyncReadGraph graph) {
+                                                       finish(graph);
+                                                       s.release();
+                                               };
+
+                                               @Override
+                                               public void exception(AsyncReadGraph graph, Throwable t) {
+                                                       except(t);
+                                                       s.release();
+                                               }
+
+                                       });
+
+                                       s.waitFor(1);
+
+                               } catch (Throwable t) {
+                                       
+                                       except(t);
+                                       
+                               }
                                
                        }