Skip to content

Commit

Permalink
Create prefer-iterable-in-flutter.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
vandadnp committed Nov 13, 2022
1 parent d1b07d7 commit 1a4acde
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 🐦 Twitter https://twitter.com/vandadnp
// πŸ”΅ LinkedIn https://linkedin.com/in/vandadnp
// πŸŽ₯ YouTube https://youtube.com/c/vandadnp
// πŸ’™ Free Flutter Course https://linktr.ee/vandadnp
// πŸ“¦ 11+ Hours Bloc Course https://youtu.be/Mn254cnduOY
// πŸ”Ά 7+ Hours MobX Course https://youtu.be/7Od55PBxYkI
// πŸ¦„ 8+ Hours RxSwift Coursde https://youtu.be/xBFWMYmm9ro
// 🀝 Want to support my work? https://buymeacoffee.com/vandad

Future<int> doHeavyComputation(int index) => Future.delayed(
const Duration(seconds: 1),
() {
'Iteration ${index + 1}'.log();
return index;
},
);

Future<void> testIt() async {
for (final future in Iterable.generate(10)
.map(
(index) => doHeavyComputation(
index,
),
)
.take(2)) {
final result = await future;
result.log();
}
}

0 comments on commit 1a4acde

Please sign in to comment.