Make AppContext API not be prone to Future oddities (#16034)

Follow-up comments to #15984
This commit is contained in:
Todd Volkert
2018-03-28 15:17:29 -07:00
committed by GitHub
parent bffae21571
commit f8058d7fb2
9 changed files with 45 additions and 45 deletions

View File

@@ -126,20 +126,20 @@ class AppContext {
/// If [name] is specified, the child context will be assigned the given
/// name. This is useful for debugging purposes and is analogous to naming a
/// thread in Java.
V run<V>({
@required V body(),
Future<V> run<V>({
@required FutureOr<V> body(),
String name,
Map<Type, Generator> overrides,
Map<Type, Generator> fallbacks,
}) {
}) async {
final AppContext child = new AppContext._(
this,
name,
new Map<Type, Generator>.unmodifiable(overrides ?? const <Type, Generator>{}),
new Map<Type, Generator>.unmodifiable(fallbacks ?? const <Type, Generator>{}),
);
return runZoned<V>(
body,
return await runZoned<Future<V>>(
() async => await body(),
zoneValues: <_Key, AppContext>{_Key.key: child},
);
}

View File

@@ -54,7 +54,7 @@ class DaemonCommand extends FlutterCommand {
Cache.releaseLockEarly();
return context.run<Future<Null>>(
return context.run<Null>(
body: () async {
final Daemon daemon = new Daemon(
stdinCommandStream, stdoutCommandResponse,

View File

@@ -38,9 +38,9 @@ Future<T> runInContext<T>(
FutureOr<T> runner(), {
Map<Type, dynamic> overrides,
}) async {
return await context.run<Future<T>>(
return await context.run<T>(
name: 'global fallbacks',
body: () async => await runner(),
body: runner,
overrides: overrides,
fallbacks: <Type, Generator>{
AndroidSdk: AndroidSdk.locateAndroidSdk,

View File

@@ -225,7 +225,7 @@ abstract class FlutterCommand extends Command<Null> {
Future<Null> run() {
final DateTime startTime = clock.now();
return context.run<Future<Null>>(
return context.run<Null>(
name: 'command',
overrides: <Type, Generator>{FlutterCommand: () => this},
body: () async {

View File

@@ -246,7 +246,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
});
}
await context.run<Future<Null>>(
await context.run<Null>(
overrides: contextOverrides.map<Type, Generator>((Type type, dynamic value) {
return new MapEntry<Type, Generator>(type, () => value);
}),