forked from firka/flutter
Make AppContext API not be prone to Future oddities (#16034)
Follow-up comments to #15984
This commit is contained in:
@@ -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},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user