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 /// This library enables one to create a service scope in which code can run. | 5 /// This library enables one to create a service scope in which code can run. |
6 /// | 6 /// |
7 /// A service scope is an environment in which code runs. The environment is a | 7 /// A service scope is an environment in which code runs. The environment is a |
8 /// [Zone] with added functionality. Code can be run inside a new service scope | 8 /// [Zone] with added functionality. Code can be run inside a new service scope |
9 /// by using the `fork(callback)` method. This will call `callback` inside a new | 9 /// by using the `fork(callback)` method. This will call `callback` inside a new |
10 /// service scope and will keep the scope alive until the Future returned by the | 10 /// service scope and will keep the scope alive until the Future returned by the |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 /// // add it to the current service scope with key `#dbpool`. | 56 /// // add it to the current service scope with key `#dbpool`. |
57 /// // In addition we insert a on-scope-exit callback which will be | 57 /// // In addition we insert a on-scope-exit callback which will be |
58 /// // called once the application is done. | 58 /// // called once the application is done. |
59 /// var pool = new DBPool(connections: 10); | 59 /// var pool = new DBPool(connections: 10); |
60 /// scope.register(#dbpool, pool, onScopeExit: () => pool.close()); | 60 /// scope.register(#dbpool, pool, onScopeExit: () => pool.close()); |
61 /// return runApp(); | 61 /// return runApp(); |
62 /// }).then((_) { | 62 /// }).then((_) { |
63 /// print('Server application shut down cleanly'); | 63 /// print('Server application shut down cleanly'); |
64 /// }); | 64 /// }); |
65 /// } | 65 /// } |
| 66 /// |
| 67 /// As an example, the `package:appengine/appengine.dart` package runs request |
| 68 /// handlers inside a service scope, which has most `package:gcloud` services |
| 69 /// registered. |
| 70 /// |
| 71 /// The core application code can then be independent of `package:appengine` |
| 72 /// and instead depend only on the services needed (e.g. |
| 73 /// `package:gcloud/storage.dart`) by using getters in the service library (e.g. |
| 74 /// the `storageService`) which are implemented with service scope lookups. |
66 library gcloud.service_scope; | 75 library gcloud.service_scope; |
67 | 76 |
68 import 'dart:async'; | 77 import 'dart:async'; |
69 | 78 |
70 /// The Symbol used as index in the zone map for the service scope object. | 79 /// The Symbol used as index in the zone map for the service scope object. |
71 const Symbol _ServiceScopeKey = #_gcloud.service_scope; | 80 const Symbol _ServiceScopeKey = #_gcloud.service_scope; |
72 | 81 |
73 /// An empty service scope. | 82 /// An empty service scope. |
74 /// | 83 /// |
75 /// New service scope can be created by calling [fork] on the empty | 84 /// New service scope can be created by calling [fork] on the empty |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 273 } |
265 } | 274 } |
266 | 275 |
267 class _RegisteredEntry { | 276 class _RegisteredEntry { |
268 final Object key; | 277 final Object key; |
269 final Object value; | 278 final Object value; |
270 final Function scopeExitCallback; | 279 final Function scopeExitCallback; |
271 | 280 |
272 _RegisteredEntry(this.key, this.value, this.scopeExitCallback); | 281 _RegisteredEntry(this.key, this.value, this.scopeExitCallback); |
273 } | 282 } |
OLD | NEW |