Skip to content

Instantly share code, notes, and snippets.

@pratikbutani
Created March 2, 2023 07:32
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 pratikbutani/826d59959708f35cb521bdcbfb9a6d8b to your computer and use it in GitHub Desktop.
Save pratikbutani/826d59959708f35cb521bdcbfb9a6d8b to your computer and use it in GitHub Desktop.
Dart Isolation Sample
import 'dart:isolate';
void main() async {
final receivePort = ReceivePort();
final isolate = await Isolate.spawn(doHeavyWork, receivePort.sendPort);
receivePort.listen((data) => print('Result: $data'));
}
void doHeavyWork(SendPort sendPort) {
// Perform some CPU-intensive work here
final result = 1 + 2 + 3 + 4 + 5;
print('Result from Heavy Work: $result');
sendPort.send(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment