Skip to content

Instantly share code, notes, and snippets.

@KoheiKanagu
Last active September 16, 2020 05:08
Show Gist options
  • Save KoheiKanagu/6b96d2200234c6de2f37e51fb9a4849d to your computer and use it in GitHub Desktop.
Save KoheiKanagu/6b96d2200234c6de2f37e51fb9a4849d to your computer and use it in GitHub Desktop.
success
void main() async {
final futures = <Future<String>>[
Future.delayed(
Duration(seconds: 1),
() => 'Hello1',
),
Future.delayed(
Duration(seconds: 2),
() => 'Hello2',
),
];
final waited = await Future.wait(futures);
final actual = waited.singleWhere(
(element) => element == 'Hello1',
orElse: () => 'unknown',
);
print(actual);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment