Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: lib/src/appengine_internal.dart

Issue 775043002: Add withAppEngineService() to package:appengine (Closed) Base URL: git@github.com:dart-lang/appengine.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« lib/appengine.dart ('K') | « lib/appengine.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/appengine_internal.dart
diff --git a/lib/src/appengine_internal.dart b/lib/src/appengine_internal.dart
index 3ed2cd7494bdff3f68f93c5c15367f93d936891e..0f217b69fdf9dac220897fff4c6f7c219a882c75 100644
--- a/lib/src/appengine_internal.dart
+++ b/lib/src/appengine_internal.dart
@@ -97,12 +97,17 @@ Future<ContextRegistry> initializeAppEngine() {
}
}
- var context = getDockerContext();
- var rpcService = initializeRPC();
-
- return getStorage(context).then((storage) {
- return new ContextRegistry(rpcService, storage, context);
- });
+ if (_contextRegistry != null) {
+ return new Future.value(_contextRegistry);
+ } else {
+ var context = getDockerContext();
+ var rpcService = initializeRPC();
+
+ return getStorage(context).then((storage) {
+ _contextRegistry = new ContextRegistry(rpcService, storage, context);
+ return _contextRegistry;
+ });
+ }
}
void initializeContext(Services services) {
@@ -127,14 +132,20 @@ void initializeRequestSpecificServices(Services services) {
users.registerUserService(services.users);
}
-Future runAppEngine(void handler(request, context), void onError(e, s)) {
+Future withAppEngineServices(Future callback()) {
return initializeAppEngine().then((ContextRegistry contextRegistry) {
- _contextRegistry = contextRegistry;
- var appengineServer = new AppEngineHttpServer(_contextRegistry);
- var backgroundServices = _contextRegistry.newBackgroundServices();
-
- ss.fork(() {
+ return ss.fork(() {
+ var backgroundServices = _contextRegistry.newBackgroundServices();
initializeContext(backgroundServices);
+ return callback();
+ });
+ });
+}
+
+Future runAppEngine(void handler(request, context), void onError(e, s)) {
+ return initializeAppEngine().then((ContextRegistry contextRegistry) {
wibling 2014/12/03 11:11:03 Why call initializeAppEngine here? Isn't it enou
kustermann 2014/12/03 11:14:42 Sure. Forgot to remove that wrapper. Done
+ return withAppEngineServices(() {
+ var appengineServer = new AppEngineHttpServer(_contextRegistry);
appengineServer.run((request, context) {
ss.fork(() {
initializeRequestSpecificServices(context.services);
@@ -170,7 +181,5 @@ Future runAppEngine(void handler(request, context), void onError(e, s)) {
});
return appengineServer.done;
});
-
- return new Future.value();
});
}
« lib/appengine.dart ('K') | « lib/appengine.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698