I am trying to know if an infinite recursive generator can cause a stack overflow error. I'm not sure if infinite recursion is a correct use case for generators, but I couldn't find any clues about it in the documentation.
Let's take this example:
import 'dart:async';
Stream<bool> infiniteStream(bool t) async* {
yield t;
await Future.delayed(Duration(milliseconds: 1));
yield* infiniteStream(!t);
}
void main() async {
await for (final value in infiniteStream(true)) {
print(value);
}
}
Is this a correct use of generators? Or will it cause error/performance problems after a long period of time? If this is not correct, what is the correct way to implement an infinite stream that can add events to itself in response to received events?
Also I've noticed that without Future.delayed(), dartpad crashes.