Last active
December 4, 2022 09:37
-
-
Save mutant0113/2567a606e57ab889c7b7637fa068d475 to your computer and use it in GitHub Desktop.
flutter_isolate_spawn_only_receive
This file contains hidden or 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:async'; | |
import 'dart:isolate'; | |
void main() async { | |
final receivePort = ReceivePort(); | |
final newIsolate = await Isolate.spawn(createNewIsolate, receivePort.sendPort); | |
final message = await receivePort.first; // Receive the result. | |
print("Main Isolate: $message"); // Print "Main Isolate: Hello New Isolate" | |
} | |
void createNewIsolate(SendPort sendPort) { | |
// Do some heavy tasks. | |
// Send back the result. | |
sendPort.send("Hello New Isolate"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment