Asynchrony support
Handlig Futures
Future<void> checkVersion() async {
var version = await lookUpVersion();
// Do something with version
}
- try,catch,finally를 이용해 에러를 처리할 수 있다
try {
version = await lookUpVersion();
} catch (e) {
// React to inability to look up the version
}
- async 함수에서 await를 여러번 부를 수 있음
var entrypoint = await findEntryPoint();
var exitCode = await runExecutable(entrypoint, args);
await flushThenExit(exitCode);
async 함수 선언
Future<String> lookUpVersion() async => '1.0.0';
handling streams
void main() async {
// ...
await for (final request in requestServer) {
handleRequest(request);
}
// ...
}