【发布时间】:2019-12-24 04:12:28
【问题描述】:
在继续执行其余代码之前,我需要我的异步函数等待某个表达式进行验证(例如 x == true)。
现在我正在使用这样的while循环
var x = false;
someFunction() async {
// here I want to await for
// as long as it takes for x to become true
while(!x) {
await new Future.delayed(new Duration(milliseconds: 250));
}
// i put 250 millisecond intentional delay
// to protect process from blocking.
// x is to be set true by external function
// rest of code ...
}
await someFunction();
你认为在继续执行之前等待 x 变为 true 有更好的方法吗? 谢谢
【问题讨论】: