Q: why does command.execute not work with stdin.readLineSync() in loop ?
mnazim opened this issue · 1 comments
mnazim commented
Hi, I think I am missing a concept of two here. works
functions works as expected, same thing does not work in a loop.
works() {
// this works as expected.
final command = RxCommand.createSync<String, String>((s) => s);
command.listen((s) => print("out-> $s"));
final inp = stdin.readLineSync();
command.execute(inp);
}
doesNotWork() {
// Same this does not work in a loop.
final command = RxCommand.createSync<String, String>((s) => s);
command.listen((s) => print("out-> $s"));
while (true) {
final inp = stdin.readLineSync();
command.execute(inp);
}
}
escamoteur commented
I'm not sure but I suspect it is because Dart is singlethreaded. try to ass an await Future.Delayed
in your loop and see if it works then.