본문 바로가기
Flutter(dart)

flutter 함수 동시 실행 isolate 쓰레드 예제

by janeparker 2022. 11. 15.
728x90
반응형
import 'dart:io';
import 'dart:async';
import 'dart:isolate';

void download(var msg) {
  Future(() {
    for (int i = 0; i < 5; i++) {
      sleep(Duration(seconds: 1));
      print("download함수 : ${i}");
    }
  });
}

main() {
  //동시 실행하고 싶을 때 isolate는 어떤 독립적인 쓰레드
  Isolate.spawn(download, "헨로우");

  for (int i = 0; i < 5; i++) {
    sleep(Duration(seconds: 1));
    print("main함수 : ${i}");
  }
}

 

출처: 메타코딩

728x90
반응형

'Flutter(dart)' 카테고리의 다른 글

다트 public과 private(언더스코어 _)  (0) 2022.11.15
플러터 함수 동시 실행  (0) 2022.11.15
flutter for문 반복문  (0) 2022.11.15
Could not find a file named "pubspec.yaml"  (0) 2022.11.09
플러터 build 터미널 명령어  (0) 2022.11.07