Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karabanovbs/ad28e4677245c578bdb127d729abd7e9 to your computer and use it in GitHub Desktop.
Save karabanovbs/ad28e4677245c578bdb127d729abd7e9 to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'dart:io';
// 2.8 Асинхронность
// Напишите функцию, которая считывает данные с клавиатуры до тех пор, пока не будет введен строка "exit". Функция должна возвращать Stream.
// Напишите код, который прослушивает поток и распечатывает на консоль "Введена строка stroke_name" каждый раз, когда в потоке появляется новое событие.
Stream<String> waitInput() async* {
while (true) {
var inVal = stdin.readLineSync(encoding: Encoding.getByName('utf-8'));
if (inVal == 'exit') {
break;
} else {
yield inVal;
}
}
}
void main(List<String> arguments) async {
waitInput().listen((stroke_name) {
print("Введена строка $stroke_name");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment