Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Created May 15, 2020 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukepighetti/f1e86c048a939d0264929c3380430c2f to your computer and use it in GitHub Desktop.
Save lukepighetti/f1e86c048a939d0264929c3380430c2f to your computer and use it in GitHub Desktop.
Async constructor arguments, sequential or parallel?
main() async {
print("Start");
var s = Stopwatch()..start();
/// It would be nice if getFoo() and getBar() were evaluated in parallel,
/// as if they were performed with Future.wait()
final result = Foo(await getFoo(), await getBar());
print("Stop: ${s.elapsed}");
}
class Foo {
final String foo;
final String bar;
Foo(this.foo, this.bar);
}
Future<String> getFoo() => Future.delayed(Duration(seconds: 1), () => "foo");
Future<String> getBar() => Future.delayed(Duration(seconds: 1), () => "bar");
@lukepighetti
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment