Created
May 24, 2023 06:59
-
-
Save yuki2021/3d3913d8282673513a75ce8f0f48b612 to your computer and use it in GitHub Desktop.
Completerの使い方の例
This file contains 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:async'; | |
void main() async { | |
Completer completer = Completer<String>(); | |
// 非同期処理を開始します(ここでは2秒待つだけ) | |
Future.delayed(Duration(seconds: 2)).then((_) { | |
// 非同期処理が完了したらCompleterを完成させます | |
completer.complete("Hello, World!"); | |
}); | |
// Completerの結果を待ちます | |
print(await completer.future); // "Hello, World!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment