Skip to content

Instantly share code, notes, and snippets.

@cs118651
Last active March 21, 2021 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cs118651/987eddf4e08c30334b09949a50eaa833 to your computer and use it in GitHub Desktop.
Save cs118651/987eddf4e08c30334b09949a50eaa833 to your computer and use it in GitHub Desktop.
dart-async
import 'dart:async';
void main() {
Future getName() async {
// 打印时钟
Timer.periodic(new Duration(seconds: 1), (timer) {
final tick = timer.tick;
print('时间过去$tick秒');
if (tick >= 5) {
timer.cancel();
}
});
String name = await Future.delayed(Duration(seconds: 4), () => 'shuangyu');
print(name);
}
getName();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment