OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library pub_dartlang_org.server_common; | 5 library pub_dartlang_org.server_common; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:gcloud/datastore.dart'; | 10 import 'package:gcloud/datastore.dart'; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 registerScopeExitCallback(authClient.close); | 100 registerScopeExitCallback(authClient.close); |
101 | 101 |
102 final datastore = new DatastoreImpl(authClient, projectId); | 102 final datastore = new DatastoreImpl(authClient, projectId); |
103 registerDatastoreService(datastore); | 103 registerDatastoreService(datastore); |
104 | 104 |
105 final db = new DatastoreDB(datastore); | 105 final db = new DatastoreDB(datastore); |
106 registerDbService(db); | 106 registerDbService(db); |
107 | 107 |
108 return db; | 108 return db; |
109 } | 109 } |
| 110 |
| 111 /// Wrapper function used to work around issue with running gRPC datastore on |
| 112 /// MacOS. |
| 113 /// |
| 114 /// On |
| 115 /// * linux this function simply returns `fun(dbService)` |
| 116 /// |
| 117 /// * macos this function makes a new service scope, optionally builds an |
| 118 /// apiary datastore and registers an apiary datastore in the new service |
| 119 /// scope |
| 120 /// |
| 121 Future withCorrectDatastore(Future fun(DatastoreDB db), DatastoreDB savedDb) { |
| 122 if (Platform.isMacOS) { |
| 123 return fork(() async { |
| 124 registerDbService(savedDb ?? await initializeApiaryDatastore()); |
| 125 return fun(dbService); |
| 126 }); |
| 127 } else { |
| 128 assert(dbService != null); |
| 129 return fun(dbService); |
| 130 } |
| 131 } |
OLD | NEW |