Created
March 2, 2023 07:32
-
-
Save pratikbutani/826d59959708f35cb521bdcbfb9a6d8b to your computer and use it in GitHub Desktop.
Dart Isolation Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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