Skip to content

huubao2309/dart_isolate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dart Isolate

Link: https://api.dart.dev/stable/2.7.1/dart-isolate/dart-isolate-library.html

Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages.

Why use Dart iSolate?

  • Dart is Single Threaded
  • Calculate so many on a threaded => Hang app
      for (var i = 0; i < 1000000000000; i++) {
        total += i;
      }
  • Speed up application

New Solate

Send iSolate two-ways

    // After 1s will kill isolate
    Future.delayed(Duration(seconds: 1), () {
      newIsolate.kill(priority: Isolate.immediate);
      newIsolate = null;
      print('Isolate is killed after 1s!');
    });
    Future<void> demoCompute() async {
      // Calculate a new value
      var result = await compute(calutate, 5);
      print(result);
    }

    static int calutate(int number) {
      return number * 10;
    }

About

Demo Dart IsoLate for Flutter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published