Created
May 15, 2020 01:40
-
-
Save lukepighetti/f1e86c048a939d0264929c3380430c2f to your computer and use it in GitHub Desktop.
Async constructor arguments, sequential or parallel?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://dartpad.dev/f1e86c048a939d0264929c3380430c2f