Open
Description
Dart SDK version: 2.14.2 (stable) (Wed Sep 15 12:32:06 2021 +0200) on "linux_x64"
OS: Linux
Platforms: desktop (working), web on chrome (bug)
Code:
int idx = 0;
Future<int> getValueExceptionOnEnd() async {
if (idx < 4) {
return idx++;
} else {
throw RangeError("no more ints for you!");
}
}
Stream<int> onlyWorksOnDesktop() async* {
try {
while (true) {
yield await getValueExceptionOnEnd();
}
} on RangeError {
print("all done! dart should close the stream after this.");
return;
}
}
Future<int?> _allPlatformsHelper() async {
try {
return await getValueExceptionOnEnd();
} on RangeError {
return null;
}
}
Stream<int> worksOnAllPlatforms() async* {
while (true) {
final value = await _allPlatformsHelper();
if (value == null) break;
yield value;
}
print("all done! dart should close the stream after this.");
}
void bugDemo() async {
idx = 0;
await for (var value in worksOnAllPlatforms()) {
print(value);
}
print("worksOnAllPlatforms()'s stream closed.");
idx = 0;
await for (var value in onlyWorksOnDesktop()) {
print(value);
}
//This never runs when developing for the web with flutter
//(though, interestingly, it does work with dart2js.)
print("onlyWorksOnDesktop()'s stream closed.");
}
bugDemo is being run in a Flutter app targeting desktop & the web.
Desktop output (expected):
0
1
2
3
all done! dart should close the stream after this.
worksOnAllPlatforms()'s stream closed.
0
1
2
3
all done! dart should close the stream after this.
onlyWorksOnDesktop()'s stream closed.
Web output:
0
1
2
3
all done! dart should close the stream after this.
worksOnAllPlatforms()'s stream closed.
0
1
2
3
all done! dart should close the stream after this.