Index: app/bin/server_common.dart |
diff --git a/app/bin/server_common.dart b/app/bin/server_common.dart |
index bb3a6b4211911e44910ec05afd5f31fdbfc923ee..a7640f26449804f97c5473592b53180609f71100 100644 |
--- a/app/bin/server_common.dart |
+++ b/app/bin/server_common.dart |
@@ -107,3 +107,25 @@ Future<DatastoreDB> initializeApiaryDatastore() async { |
return db; |
} |
+ |
+/// Wrapper function used to work around issue with running gRPC datastore on |
+/// MacOS. |
+/// |
+/// On |
+/// * linux this function simply returns `fun(dbService)` |
+/// |
+/// * macos this function makes a new service scope, optionally builds an |
+/// apiary datastore and registers an apiary datastore in the new service |
+/// scope |
+/// |
+Future withCorrectDatastore(Future fun(DatastoreDB db), DatastoreDB savedDb) { |
+ if (Platform.isMacOS) { |
+ return fork(() async { |
+ registerDbService(savedDb ?? await initializeApiaryDatastore()); |
+ return fun(dbService); |
+ }); |
+ } else { |
+ assert(dbService != null); |
+ return fun(dbService); |
+ } |
+} |