화염의 형태 공방 불의 형태 24일째 : Dart의 Sleep 기능!! Scratch와 비교해 보자
기사 키지입니다.
Sleep 기능 키노우를 이용하자.
전회 젠카이의 방법 쪽이라면, 메시지가 굉장한 기세로 흐르게 되어 가므로, 사이의 사이에 Sleep를 들어가 봅시다.

Dart로 작성해 봅시다.
import 'dart:math' as math;
import 'dart:async';
main(List<String> args) async {
var rand = new math.Random();
var messages = ["hello", "bye"];
while(true) {
print("${messages[rand.nextInt(2)]}");
await new Future.delayed(new Duration(seconds: 1));
}
}
Sleep 기능을 사용하려면 dart : async 패키지를 사용하십시오.
패키지를 선언하지 않는다
import 'dart:async';
main 함수 kansuu에 async를 정의합니다.
main(List<String> args) async {
}
1초쯤 sleep하는 코드 쓰기
await new Future.delayed(new Duration(seconds: 1));
await를 선언하지 않는 것으로, 1초만 그 자리에서 기다리게 됩니다.
await을 이용하고 싶은 경우에는 함수 칸수에게 async 선언 센겐을 할 필요가 있습니다.
Thanks
지금까지 읽어 주셔서 감사합니다!
그렇다면 다음 번에 만나는 것을 즐거운 느낌으로하고 있습니다.
그럼
Reference
이 문제에 관하여(화염의 형태 공방 불의 형태 24일째 : Dart의 Sleep 기능!! Scratch와 비교해 보자), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kyorohiro/items/fe6790055f0a160c4f72
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import 'dart:math' as math;
import 'dart:async';
main(List<String> args) async {
var rand = new math.Random();
var messages = ["hello", "bye"];
while(true) {
print("${messages[rand.nextInt(2)]}");
await new Future.delayed(new Duration(seconds: 1));
}
}
import 'dart:async';
main(List<String> args) async {
}
await new Future.delayed(new Duration(seconds: 1));
Reference
이 문제에 관하여(화염의 형태 공방 불의 형태 24일째 : Dart의 Sleep 기능!! Scratch와 비교해 보자), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kyorohiro/items/fe6790055f0a160c4f72텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)