I want to check if there is any Future.delayed function ongoing. Thanks for any help.
Future.delayed(duration, () async {
await aFunction();
});
bool isAnyDelayedAtTheMoment=?;
As theiskaa suggested, i did like this:
bool isAnyDelayedAtTheMoment=true;
Future.delayed(duration, () async {
await aFunction();
isAnyDelayedAtTheMoment=false;
});
as an option you can use Completed
full code:
import 'dart:async';
void main() {
final completer = Completer();
Future.delayed(Duration(seconds: 1), () async {
await aFunction();
completer.complete();
});
print('isCompleted: ${completer.isCompleted}'); // false
Future.delayed(Duration(seconds: 2), () async {
print('isCompleted: ${completer.isCompleted}'); // true
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.