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

Unified Diff: lib/appengine.dart

Issue 775043002: Add withAppEngineService() to package:appengine (Closed) Base URL: git@github.com:dart-lang/appengine.git@master
Patch Set: Rebased on HEAD 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
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/appengine_internal.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/appengine.dart
diff --git a/lib/appengine.dart b/lib/appengine.dart
index a05144d93135a84fe302d6d48392bc331114c7f1..c424f9bb529c4055083ab5fb05ed3957509f496c 100644
--- a/lib/appengine.dart
+++ b/lib/appengine.dart
@@ -7,13 +7,13 @@ library appengine;
import 'dart:async';
import 'dart:io';
+export 'package:gcloud/http.dart';
import 'package:gcloud/service_scope.dart' as ss;
import 'src/appengine_internal.dart' as appengine_internal;
import 'src/app_engine_request_handler.dart';
import 'src/client_context.dart';
-export 'package:gcloud/http.dart';
export 'api/errors.dart';
export 'api/logging.dart';
export 'api/modules.dart';
@@ -43,6 +43,9 @@ const Symbol _APPENGINE_CONTEXT = #appengine.context;
* The [onError] function can take either the error object, or the error object
* and a stack as an argument. If [onError] was not provided, errors will get
* printed out to the stdout of this process.
+ *
+ * The returned `Future` will complete when the HTTP server has been shutdown
+ * and is no longer serving requests.
*/
Future runAppEngine(AppEngineRequestHandler handler, {Function onError}) {
var errorHandler;
@@ -69,6 +72,48 @@ Future runAppEngine(AppEngineRequestHandler handler, {Function onError}) {
}
/**
+ * Runs [callback] inside a new service scope with appengine services added.
+ *
+ * The services available to `callback` are all non-request specific appengine
+ * services e.g. `memcacheService`, `dbService`.
+ *
+ * See `package:gcloud/service_scope.dart` for more information on service
+ * scopes.
+ *
+ * Here is an example on how this can be used:
+ *
+ * import 'dart:async';
+ * import 'dart:io';
+ * import 'package:appengine/appengine.dart';
+ *
+ * Future backgroundWork() {
+ * return dbService.query(Person).run().toList().then((persons) {
+ * // Do something with `persons`.
+ * });
+ * }
+ *
+ * void mainHandler(HttpRequest request) {
+ * dbService.query(Greeting).run().toList().then((greetings) {
+ * request.response
+ * ..write('Number of greetings: ${greetings.length}')
+ * ..close();
+ * });
+ * }
+ *
+ * main() {
+ * withAppEngineServices(() {
+ * return Future.wait([
+ * runAppEngine(mainHandler),
+ * backgroundWork(),
+ * ]);
+ * });
+ * }
+ */
+Future withAppEngineServices(Future callback()) {
+ return appengine_internal.withAppEngineServices(callback);
+}
+
+/**
* Returns the [ClientContext] of the current request.
*
* This getter can only be called inside a request handler which was passed to
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/appengine_internal.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698