diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
index ad9897bb..fbbbfdf7 100644
--- a/.idea/libraries/Dart_Packages.xml
+++ b/.idea/libraries/Dart_Packages.xml
@@ -519,6 +519,7 @@
+
\ No newline at end of file
diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml
index 2255dbd8..ed937c05 100644
--- a/.idea/libraries/Dart_SDK.xml
+++ b/.idea/libraries/Dart_SDK.xml
@@ -21,6 +21,7 @@
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/Match_routes__even_with_query_params_in_routing_test_dart.xml b/.idea/runConfigurations/Match_routes__even_with_query_params_in_routing_test_dart.xml
new file mode 100644
index 00000000..3df4dee3
--- /dev/null
+++ b/.idea/runConfigurations/Match_routes__even_with_query_params_in_routing_test_dart.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/can_fetch_data_in_services_test_dart.xml b/.idea/runConfigurations/can_fetch_data_in_services_test_dart.xml
new file mode 100644
index 00000000..5dbab496
--- /dev/null
+++ b/.idea/runConfigurations/can_fetch_data_in_services_test_dart.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 73da9b1a..df55ab7d 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,9 +2,44 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -27,36 +62,29 @@
-
-
+
+
-
-
-
-
-
+
+
-
-
+
+
-
-
-
-
-
+
+
-
-
+
+
-
-
-
+
+
@@ -64,8 +92,8 @@
-
-
+
+
@@ -73,52 +101,68 @@
-
-
+
+
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
+
+
-
-
+
+
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
+
+
+
+
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -135,28 +179,6 @@
- _isOpen
- _isClosed
- end
- isOpen
- _useStream
- isClosed
- HttpHeaders.
- = false
- = true
- Future
- toId
- createZ
- default
- catch
- error
- trace
- zonesp
- runGuar
- unca
- async
- hey
- match
getV
zone
zone.run
@@ -165,11 +187,30 @@
statusCode
.run
var body = await rs.fold<List<int>>([], (out, list) => []..addAll(list));
+ async =
+ async {
+ await
+ e read(
+ for (var ha
+ geth
+ pip
+ close
+ sendFile
+ getHan
+ gethandle
+ BANG
+ execute
+ lazyBod
+ lazyBody()
+ addRout
+ lazyBody
+ _body = nu
+ _body
+ MID
+ beforeIndex
+ read(
- _isClosed
- // _printDebug
- create
modify
update
remove
@@ -195,6 +236,11 @@
'server'
FutureOr
var body = await getBody(rs);
+
+ =
+ =
+ {
+
C:\Users\thosa\Source\Angel\framework\lib
@@ -202,6 +248,7 @@
C:\Users\thosa\Source\Angel\framework\test
$PROJECT_DIR$/lib/src
$PROJECT_DIR$/test
+ $PROJECT_DIR$/lib/src/core
$PROJECT_DIR$/lib
@@ -213,65 +260,60 @@
-
-
-
@@ -281,9 +323,12 @@
true
DEFINITION_ORDER
+
+
+
-
-
+
+
@@ -292,23 +337,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -319,32 +350,36 @@
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
+
+
@@ -365,96 +400,17 @@
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
- project
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- project
-
-
- true
-
-
-
- DIRECTORY
-
- false
-
-
@@ -492,11 +448,16 @@
-
+
+
+
+
+
+
@@ -555,58 +516,86 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ project
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
@@ -679,14 +668,9 @@
-
-
-
- 1506092029287
-
-
-
- 1506092029287
+
+
+
1506092171442
@@ -1024,43 +1008,50 @@
1526440469836
-
+
+ 1526440683707
+
+
+
+ 1526440683707
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
@@ -1072,43 +1063,47 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1119,7 +1114,6 @@
-
@@ -1144,297 +1138,267 @@
-
+
+
-
+
-
-
+
+
+
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
@@ -1443,111 +1407,138 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8dad1665..7ecac991 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# 1.1.4
+* Remove all usages of `async`/`await` in the core library.
+* `AngelConfigurer` now accepts `FutureOr`.
+* `AngelHttp` now has a `useZone` flag to disable custom zones.
+
# 1.1.3
* `AngelHttp` now handles requests in a `Zone`.
* Use `package:dart2_constant`.
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 518eb901..1167d894 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,2 +1,5 @@
analyzer:
- strong-mode: true
\ No newline at end of file
+ strong-mode: true
+linter:
+ rules:
+ - avoid_slow_async_io
\ No newline at end of file
diff --git a/example/json.dart b/example/json.dart
index 1ab77456..27426ba9 100644
--- a/example/json.dart
+++ b/example/json.dart
@@ -1,5 +1,4 @@
import 'dart:async';
-import 'dart:io';
import 'dart:isolate';
import 'package:dart2_constant/convert.dart';
import 'package:angel_framework/angel_framework.dart';
@@ -48,6 +47,6 @@ serverMain(_) async {
print(e.stackTrace);
};
- var server = await http.startServer(InternetAddress.LOOPBACK_IP_V4, 3000);
+ var server = await http.startServer('127.0.0.1', 3000);
print('Listening at http://${server.address.address}:${server.port}');
}
diff --git a/lib/hooks.dart b/lib/hooks.dart
index 13c18a3d..bcce6141 100644
--- a/lib/hooks.dart
+++ b/lib/hooks.dart
@@ -9,19 +9,19 @@ import 'angel_framework.dart';
/// Sequentially runs a set of [listeners].
HookedServiceEventListener chainListeners(
Iterable listeners) {
- return (HookedServiceEvent e) async {
- for (HookedServiceEventListener listener in listeners) await listener(e);
+ return (HookedServiceEvent e) {
+ for (HookedServiceEventListener listener in listeners) listener(e);
};
}
/// Runs a [callback] on every service, and listens for future services to run it again.
AngelConfigurer hookAllServices(callback(Service service)) {
- return (Angel app) async {
+ return (Angel app) {
List touched = [];
for (var service in app.services.values) {
if (!touched.contains(service)) {
- await callback(service);
+ callback(service);
touched.add(service);
}
}
@@ -52,9 +52,9 @@ HookedServiceEventListener transform(transformer(obj), [condition]) {
Iterable cond = condition is Iterable ? condition : [condition];
if (condition == null) cond = [];
- _condition(HookedServiceEvent e, condition) async {
+ _condition(HookedServiceEvent e, condition) {
if (condition is Function)
- return await condition(e);
+ return condition(e);
else if (condition == Providers)
return true;
else {
@@ -70,11 +70,11 @@ HookedServiceEventListener transform(transformer(obj), [condition]) {
}
}
- normalize(HookedServiceEvent e, obj) async {
+ normalize(HookedServiceEvent e, obj) {
bool transform = true;
for (var c in cond) {
- var r = await _condition(e, c);
+ var r = _condition(e, c);
if (r != true) {
transform = false;
@@ -97,7 +97,7 @@ HookedServiceEventListener transform(transformer(obj), [condition]) {
var r = [];
for (var o in obj) {
- r.add(await normalize(e, o));
+ r.add(normalize(e, o));
}
return r;
@@ -105,10 +105,10 @@ HookedServiceEventListener transform(transformer(obj), [condition]) {
return transformer(obj);
}
- return (HookedServiceEvent e) async {
+ return (HookedServiceEvent e) {
if (e.isBefore) {
- e.data = await normalize(e, e.data);
- } else if (e.isAfter) e.result = await normalize(e, e.result);
+ e.data = normalize(e, e.data);
+ } else if (e.isAfter) e.result = normalize(e, e.result);
};
}
@@ -135,7 +135,7 @@ HookedServiceEventListener toType(Type type) {
/// Only applies to the client-side.
HookedServiceEventListener remove(key, [remover(key, obj)]) {
return (HookedServiceEvent e) async {
- _remover(key, obj) {
+ _remover(key, obj) async {
if (remover != null)
return remover(key, obj);
else if (obj is List)
@@ -171,15 +171,15 @@ HookedServiceEventListener remove(key, [remover(key, obj)]) {
if (obj is Iterable) {
return await Future.wait(obj.map(_removeAll));
} else
- return await _removeAll(obj);
+ return _removeAll(obj);
}
}
if (e.params?.containsKey('provider') == true) {
if (e.isBefore) {
- e.data = await normalize(e.data);
+ e.data = normalize(e.data);
} else if (e.isAfter) {
- e.result = await normalize(e.result);
+ e.result = normalize(e.result);
}
}
};
@@ -193,12 +193,12 @@ HookedServiceEventListener remove(key, [remover(key, obj)]) {
///
/// If [provider] is `null`, then it will be disabled to all clients.
HookedServiceEventListener disable([provider]) {
- return (HookedServiceEvent e) async {
+ return (HookedServiceEvent e) {
if (e.params.containsKey('provider')) {
if (provider == null)
throw new AngelHttpException.methodNotAllowed();
else if (provider is Function) {
- var r = await provider(e);
+ var r = provider(e);
if (r != true) throw new AngelHttpException.methodNotAllowed();
} else {
_provide(p) => p is Providers ? p : new Providers(p.toString());
@@ -224,7 +224,7 @@ HookedServiceEventListener addCreatedAt(
{assign(obj, now), String key, bool serialize: true}) {
var name = key?.isNotEmpty == true ? key : 'createdAt';
- return (HookedServiceEvent e) async {
+ return (HookedServiceEvent e) {
_assign(obj, now) {
if (assign != null)
return assign(obj, now);
@@ -242,17 +242,17 @@ HookedServiceEventListener addCreatedAt(
var d = new DateTime.now().toUtc();
var now = serialize == false ? d : d.toIso8601String();
- normalize(obj) async {
+ normalize(obj) {
if (obj != null) {
if (obj is Iterable) {
obj.forEach(normalize);
} else {
- await _assign(obj, now);
+ _assign(obj, now);
}
}
}
- await normalize(e.isBefore ? e.data : e.result);
+ normalize(e.isBefore ? e.data : e.result);
};
}
@@ -265,7 +265,7 @@ HookedServiceEventListener addUpdatedAt(
{assign(obj, now), String key, bool serialize: true}) {
var name = key?.isNotEmpty == true ? key : 'updatedAt';
- return (HookedServiceEvent e) async {
+ return (HookedServiceEvent e) {
_assign(obj, now) {
if (assign != null)
return assign(obj, now);
@@ -283,16 +283,16 @@ HookedServiceEventListener addUpdatedAt(
var d = new DateTime.now().toUtc();
var now = serialize == false ? d : d.toIso8601String();
- normalize(obj) async {
+ normalize(obj) {
if (obj != null) {
if (obj is Iterable) {
obj.forEach(normalize);
} else {
- await _assign(obj, now);
+ _assign(obj, now);
}
}
}
- await normalize(e.isBefore ? e.data : e.result);
+ normalize(e.isBefore ? e.data : e.result);
};
}
diff --git a/lib/src/core/angel_base.dart b/lib/src/core/angel_base.dart
index 3bc8c7b6..bf055630 100644
--- a/lib/src/core/angel_base.dart
+++ b/lib/src/core/angel_base.dart
@@ -9,9 +9,8 @@ typedef Future ViewGenerator(String path, [Map data]);
/// Base class for Angel servers. Do not bother extending this.
class AngelBase extends Routable {
- static ViewGenerator noViewEngineConfigured = (String view,
- [Map data]) async =>
- "No view engine has been configured yet.";
+ static ViewGenerator noViewEngineConfigured = (String view, [Map data]) =>
+ new Future.value("No view engine has been configured yet.");
Container _container = new Container();
@@ -35,9 +34,10 @@ class AngelBase extends Routable {
ViewGenerator viewGenerator = noViewEngineConfigured;
/// Closes this instance, rendering it **COMPLETELY DEFUNCT**.
- Future close() async {
- await super.close();
+ Future close() {
+ super.close();
_container = null;
viewGenerator = noViewEngineConfigured;
+ return new Future.value();
}
}
diff --git a/lib/src/core/hooked_service.dart b/lib/src/core/hooked_service.dart
index 51580c8c..ef500a9a 100644
--- a/lib/src/core/hooked_service.dart
+++ b/lib/src/core/hooked_service.dart
@@ -67,7 +67,7 @@ class HookedService extends Service {
/// Closes any open [StreamController]s on this instance. **Internal use only**.
@override
- Future close() async {
+ Future close() {
_ctrl.forEach((c) => c.close());
beforeIndexed._close();
beforeRead._close();
@@ -81,7 +81,8 @@ class HookedService extends Service {
afterModified._close();
afterUpdated._close();
afterRemoved._close();
- await inner.close();
+ inner.close();
+ return new Future.value();
}
/// Adds hooks to this instance.
@@ -120,149 +121,16 @@ class HookedService extends Service {
applyListeners(inner.remove, afterRemoved, true);
}
- /// Adds routes to this instance.
- @override
- void addRoutes() {
- // Set up our routes. We still need to copy middleware from inner service
- Map restProvider = {'provider': Providers.rest};
+ List get bootstrappers => new List.from(super.bootstrappers)
+ ..add((RequestContext req, ResponseContext res) {
+ req.serviceParams
+ ..['__requestctx'] = req
+ ..['__responsectx'] = res;
+ return true;
+ });
- // Add global middleware if declared on the instance itself
- Middleware before = getAnnotation(inner, Middleware);
- List handlers = [
- (RequestContext req, ResponseContext res) async {
- req.serviceParams
- ..['__requestctx'] = req
- ..['__responsectx'] = res;
- return true;
- }
- ];
-
- if (before != null) handlers.addAll(before.handlers);
-
- Middleware indexMiddleware = getAnnotation(inner.index, Middleware);
- get('/', (req, res) async {
- return await this.index(mergeMap([
- {'query': req.query},
- restProvider,
- req.serviceParams
- ]));
- },
- middleware: []
- ..addAll(handlers)
- ..addAll((indexMiddleware == null) ? [] : indexMiddleware.handlers));
-
- Middleware createMiddleware = getAnnotation(inner.create, Middleware);
-
- post('/', (req, res) async {
- var r = await this.create(
- await req.lazyBody(),
- mergeMap([
- {'query': req.query},
- restProvider,
- req.serviceParams
- ]));
- res.statusCode = 201;
- return r;
- },
- middleware: []
- ..addAll(handlers)
- ..addAll(
- (createMiddleware == null) ? [] : createMiddleware.handlers));
-
- Middleware readMiddleware = getAnnotation(inner.read, Middleware);
-
- get(
- '/:id',
- (req, res) async => await this.read(
- toId(req.params['id']),
- mergeMap([
- {'query': req.query},
- restProvider,
- req.serviceParams
- ])),
- middleware: []
- ..addAll(handlers)
- ..addAll((readMiddleware == null) ? [] : readMiddleware.handlers));
-
- Middleware modifyMiddleware = getAnnotation(inner.modify, Middleware);
- patch(
- '/:id',
- (req, res) async => await this.modify(
- toId(req.params['id']),
- await req.lazyBody(),
- mergeMap([
- {'query': req.query},
- restProvider,
- req.serviceParams
- ])),
- middleware: []
- ..addAll(handlers)
- ..addAll(
- (modifyMiddleware == null) ? [] : modifyMiddleware.handlers));
-
- Middleware updateMiddleware = getAnnotation(inner.update, Middleware);
- post(
- '/:id',
- (req, res) async => await this.update(
- toId(req.params['id']),
- await req.lazyBody(),
- mergeMap([
- {'query': req.query},
- restProvider,
- req.serviceParams
- ])),
- middleware: []
- ..addAll(handlers)
- ..addAll(
- (updateMiddleware == null) ? [] : updateMiddleware.handlers));
- put(
- '/:id',
- (req, res) async => await this.update(
- toId(req.params['id']),
- await req.lazyBody(),
- mergeMap([
- {'query': req.query},
- restProvider,
- req.serviceParams
- ])),
- middleware: []
- ..addAll(handlers)
- ..addAll(
- (updateMiddleware == null) ? [] : updateMiddleware.handlers));
-
- Middleware removeMiddleware = getAnnotation(inner.remove, Middleware);
- delete(
- '/',
- (req, res) async => await this.remove(
- null,
- mergeMap([
- {'query': req.query},
- restProvider,
- req.serviceParams
- ])),
- middleware: []
- ..addAll(handlers)
- ..addAll(
- (removeMiddleware == null) ? [] : removeMiddleware.handlers));
- delete(
- '/:id',
- (req, res) async => await this.remove(
- toId(req.params['id']),
- mergeMap([
- {'query': req.query},
- restProvider,
- req.serviceParams
- ])),
- middleware: []
- ..addAll(handlers)
- ..addAll(
- (removeMiddleware == null) ? [] : removeMiddleware.handlers));
-
- // REST compliance
- put('/', () => throw new AngelHttpException.notFound());
- patch('/', () => throw new AngelHttpException.notFound());
-
- addHooks();
+ void addRoutes([Service s]) {
+ super.addRoutes(s ?? inner);
}
/// Runs the [listener] before every service method specified.
@@ -388,192 +256,165 @@ class HookedService extends Service {
}
@override
- Future index([Map _params]) async {
+ Future index([Map _params]) {
var params = _stripReq(_params);
- HookedServiceEvent before = await beforeIndexed._emit(
- new HookedServiceEvent(false, _getRequest(_params),
+ return beforeIndexed
+ ._emit(new HookedServiceEvent(false, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.indexed,
- params: params));
- if (before._canceled) {
- HookedServiceEvent after = await beforeIndexed._emit(
- new HookedServiceEvent(true, _getRequest(_params),
- _getResponse(_params), inner, HookedServiceEvent.indexed,
- params: params, result: before.result));
- return after.result;
- }
+ params: params))
+ .then((before) {
+ if (before._canceled) {
+ return beforeIndexed
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.indexed,
+ params: params, result: before.result))
+ .then((after) => after.result);
+ }
- var result = await inner.index(params);
- HookedServiceEvent after = await afterIndexed._emit(new HookedServiceEvent(
- true,
- _getRequest(_params),
- _getResponse(_params),
- inner,
- HookedServiceEvent.indexed,
- params: params,
- result: result));
- return after.result;
+ return inner.index(params).then((result) {
+ return afterIndexed
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.indexed,
+ params: params, result: result))
+ .then((after) => after.result);
+ });
+ });
}
@override
- Future read(id, [Map _params]) async {
+ Future read(id, [Map _params]) {
var params = _stripReq(_params);
- HookedServiceEvent before = await beforeRead._emit(new HookedServiceEvent(
- false,
- _getRequest(_params),
- _getResponse(_params),
- inner,
- HookedServiceEvent.indexed,
- id: id,
- params: params));
+ return beforeRead
+ ._emit(new HookedServiceEvent(false, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.read,
+ id: id, params: params))
+ .then((before) {
+ if (before._canceled) {
+ return beforeRead
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.read,
+ id: id, params: params, result: before.result))
+ .then((after) => after.result);
+ }
- if (before._canceled) {
- HookedServiceEvent after = await afterRead._emit(new HookedServiceEvent(
- true,
- _getRequest(_params),
- _getResponse(_params),
- inner,
- HookedServiceEvent.read,
- id: id,
- params: params,
- result: before.result));
- return after.result;
- }
-
- var result = await inner.read(id, params);
- HookedServiceEvent after = await afterRead._emit(new HookedServiceEvent(
- true,
- _getRequest(_params),
- _getResponse(_params),
- inner,
- HookedServiceEvent.read,
- id: id,
- params: params,
- result: result));
- return after.result;
+ return inner.read(id, params).then((result) {
+ return afterRead
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.read,
+ id: id, params: params, result: result))
+ .then((after) => after.result);
+ });
+ });
}
@override
- Future create(data, [Map _params]) async {
+ Future create(data, [Map _params]) {
var params = _stripReq(_params);
- HookedServiceEvent before = await beforeCreated._emit(
- new HookedServiceEvent(false, _getRequest(_params),
+ return beforeCreated
+ ._emit(new HookedServiceEvent(false, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.created,
- data: data, params: params));
+ data: data, params: params))
+ .then((before) {
+ if (before._canceled) {
+ return beforeCreated
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.created,
+ data: data, params: params, result: before.result))
+ .then((after) => after.result);
+ }
- if (before._canceled) {
- HookedServiceEvent after = await afterCreated._emit(
- new HookedServiceEvent(true, _getRequest(_params),
- _getResponse(_params), inner, HookedServiceEvent.created,
- data: data, params: params, result: before.result));
- return after.result;
- }
-
- var result = await inner.create(data, params);
- HookedServiceEvent after = await afterCreated._emit(new HookedServiceEvent(
- true,
- _getRequest(_params),
- _getResponse(_params),
- inner,
- HookedServiceEvent.created,
- data: data,
- params: params,
- result: result));
- return after.result;
+ return inner.create(data, params).then((result) {
+ return afterCreated
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.created,
+ data: data, params: params, result: result))
+ .then((after) => after.result);
+ });
+ });
}
@override
- Future modify(id, data, [Map _params]) async {
+ Future modify(id, data, [Map _params]) {
var params = _stripReq(_params);
- HookedServiceEvent before = await beforeModified._emit(
- new HookedServiceEvent(false, _getRequest(_params),
+ return beforeModified
+ ._emit(new HookedServiceEvent(false, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.modified,
- id: id, data: data, params: params));
+ id: id, data: data, params: params))
+ .then((before) {
+ if (before._canceled) {
+ return beforeModified
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.modified,
+ id: id, data: data, params: params, result: before.result))
+ .then((after) => after.result);
+ }
- if (before._canceled) {
- HookedServiceEvent after = await afterModified._emit(
- new HookedServiceEvent(true, _getRequest(_params),
- _getResponse(_params), inner, HookedServiceEvent.modified,
- id: id, data: data, params: params, result: before.result));
- return after.result;
- }
-
- var result = await inner.modify(id, data, params);
- HookedServiceEvent after = await afterModified._emit(new HookedServiceEvent(
- true,
- _getRequest(_params),
- _getResponse(_params),
- inner,
- HookedServiceEvent.modified,
- id: id,
- data: data,
- params: params,
- result: result));
- return after.result;
+ return inner.modify(id, data, params).then((result) {
+ return afterModified
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.created,
+ id: id, data: data, params: params, result: result))
+ .then((after) => after.result);
+ });
+ });
}
@override
- Future update(id, data, [Map _params]) async {
+ Future update(id, data, [Map _params]) {
var params = _stripReq(_params);
- HookedServiceEvent before = await beforeUpdated._emit(
- new HookedServiceEvent(false, _getRequest(_params),
+ return beforeUpdated
+ ._emit(new HookedServiceEvent(false, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.updated,
- id: id, data: data, params: params));
+ id: id, data: data, params: params))
+ .then((before) {
+ if (before._canceled) {
+ return beforeUpdated
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.updated,
+ id: id, data: data, params: params, result: before.result))
+ .then((after) => after.result);
+ }
- if (before._canceled) {
- HookedServiceEvent after = await afterUpdated._emit(
- new HookedServiceEvent(true, _getRequest(_params),
- _getResponse(_params), inner, HookedServiceEvent.updated,
- id: id, data: data, params: params, result: before.result));
- return after.result;
- }
-
- var result = await inner.update(id, data, params);
- HookedServiceEvent after = await afterUpdated._emit(new HookedServiceEvent(
- true,
- _getRequest(_params),
- _getResponse(_params),
- inner,
- HookedServiceEvent.updated,
- id: id,
- data: data,
- params: params,
- result: result));
- return after.result;
+ return inner.update(id, data, params).then((result) {
+ return afterUpdated
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.updated,
+ id: id, data: data, params: params, result: result))
+ .then((after) => after.result);
+ });
+ });
}
@override
- Future remove(id, [Map _params]) async {
+ Future remove(id, [Map _params]) {
var params = _stripReq(_params);
- HookedServiceEvent before = await beforeRemoved._emit(
- new HookedServiceEvent(false, _getRequest(_params),
+ return beforeRemoved
+ ._emit(new HookedServiceEvent(false, _getRequest(_params),
_getResponse(_params), inner, HookedServiceEvent.removed,
- id: id, params: params));
+ id: id, params: params))
+ .then((before) {
+ if (before._canceled) {
+ return beforeRemoved
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.removed,
+ id: id, params: params, result: before.result))
+ .then((after) => after.result);
+ }
- if (before._canceled) {
- HookedServiceEvent after = await afterRemoved._emit(
- new HookedServiceEvent(true, _getRequest(_params),
- _getResponse(_params), inner, HookedServiceEvent.removed,
- id: id, params: params, result: before.result));
- return after.result;
- }
-
- var result = await inner.remove(id, params);
- HookedServiceEvent after = await afterRemoved._emit(new HookedServiceEvent(
- true,
- _getRequest(_params),
- _getResponse(_params),
- inner,
- HookedServiceEvent.removed,
- id: id,
- params: params,
- result: result));
- return after.result;
+ return inner.remove(id, params).then((result) {
+ return afterRemoved
+ ._emit(new HookedServiceEvent(true, _getRequest(_params),
+ _getResponse(_params), inner, HookedServiceEvent.removed,
+ id: id, params: params, result: result))
+ .then((after) => after.result);
+ });
+ });
}
/// Fires an `after` event. This will not be propagated to clients,
/// but will be broadcasted to WebSockets, etc.
Future fire(String eventName, result,
- [HookedServiceEventListener callback]) async {
+ [HookedServiceEventListener callback]) {
HookedServiceEventDispatcher dispatcher;
switch (eventName) {
@@ -600,15 +441,15 @@ class HookedService extends Service {
}
var ev = new HookedServiceEvent(true, null, null, this, eventName);
- return await fireEvent(dispatcher, ev, callback);
+ return fireEvent(dispatcher, ev, callback);
}
/// Sends an arbitrary event down the hook chain.
Future fireEvent(
HookedServiceEventDispatcher dispatcher, HookedServiceEvent event,
- [HookedServiceEventListener callback]) async {
- if (callback != null && event?._canceled != true) await callback(event);
- return await dispatcher._emit(event);
+ [HookedServiceEventListener callback]) {
+ if (callback != null && event?._canceled != true) callback(event);
+ return dispatcher._emit(event);
}
}
@@ -690,16 +531,16 @@ class HookedServiceEventDispatcher {
}
/// Fires an event, and returns it once it is either canceled, or all listeners have run.
- Future _emit(HookedServiceEvent event) async {
+ Future _emit(HookedServiceEvent event) {
if (event?._canceled != true) {
for (var listener in listeners) {
- await listener(event);
+ listener(event);
- if (event._canceled) return event;
+ if (event._canceled) return new Future.value(event);
}
}
- return event;
+ return new Future.value(event);
}
/// Returns a [Stream] containing all events fired by this dispatcher.
diff --git a/lib/src/core/injection.dart b/lib/src/core/injection.dart
index fba314ab..b9594642 100644
--- a/lib/src/core/injection.dart
+++ b/lib/src/core/injection.dart
@@ -78,10 +78,11 @@ bool suitableForInjection(
/// Handles a request with a DI-enabled handler.
RequestHandler handleContained(handler, InjectionRequest injection) {
- return (RequestContext req, ResponseContext res) async {
+ return (RequestContext req, ResponseContext res) {
if (injection.parameters.isNotEmpty &&
injection.parameters.values.any((p) => p.match != null) &&
- !suitableForInjection(req, res, injection)) return true;
+ !suitableForInjection(req, res, injection))
+ return new Future.value(true);
List args = [];
@@ -94,8 +95,7 @@ RequestHandler handleContained(handler, InjectionRequest injection) {
named[name] = resolveInjection([k, v], injection, req, res, false);
});
- var result = Function.apply(handler, args, named);
- return result is Future ? await result : result;
+ return Function.apply(handler, args, named);
};
}
@@ -181,6 +181,5 @@ InjectionRequest preInject(Function handler) {
injection.named[name] = type;
}
}
-
return injection;
}
diff --git a/lib/src/core/map_service.dart b/lib/src/core/map_service.dart
index 9f89f0f0..3f2d9e90 100644
--- a/lib/src/core/map_service.dart
+++ b/lib/src/core/map_service.dart
@@ -45,13 +45,13 @@ class MapService extends Service {
}
@override
- Future index([Map params]) async {
+ Future index([Map params]) {
if (allowQuery == false || params == null || params['query'] is! Map)
- return items;
+ return new Future.value(items);
else {
Map query = params['query'];
- return items.where((item) {
+ return new Future.value(items.where((item) {
for (var key in query.keys) {
if (!item.containsKey(key))
return false;
@@ -59,19 +59,19 @@ class MapService extends Service {
}
return true;
- }).toList();
+ }).toList());
}
}
@override
- Future