Created
November 29, 2020 05:27
-
-
Save karabanovbs/ad28e4677245c578bdb127d729abd7e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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