sanpwc commented on a change in pull request #149:
URL: https://github.com/apache/ignite-3/pull/149#discussion_r642274352



##########
File path: 
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
##########
@@ -397,6 +387,74 @@ private void listenForTableChange() {
 
     /** {@inheritDoc} */
     @Override public Table table(String name) {
-        return tables.get(name);
+        if (!isTableConfigured(name))
+            throw new IgniteException("Table wasn't found [name=" + name + 
']');
+
+        Table tbl = tables.get(name);
+
+        if (tbl != null)
+            return tbl;
+
+        CompletableFuture<Table> getTblFut = new CompletableFuture<>();
+
+        BiPredicate<TableEventParameters, Throwable> clo = (params, e) -> {
+            String tableName = params.tableName();
+
+            if (!name.equals(tableName))
+                return false;
+
+            if (e == null)
+                getTblFut.complete(params.table());
+            else
+                getTblFut.completeExceptionally(e);
+
+            return true;
+        };
+
+        listen(TableEvent.CREATE, clo);
+
+        tbl = tables.get(name);
+
+        if (tbl != null && getTblFut.complete(tbl) ||
+            !isTableConfigured(name) && getTblFut.completeExceptionally(new 
IgniteException("Table was removed [name=" + name + ']')))
+            removeListener(TableEvent.CREATE, clo);
+
+        return getTblFut.join();

Review comment:
       Do we expect use to handle CompletionException?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to