Skip to content

Instantly share code, notes, and snippets.

@mutant0113
Last active December 4, 2022 09:37
Show Gist options
  • Save mutant0113/2567a606e57ab889c7b7637fa068d475 to your computer and use it in GitHub Desktop.
Save mutant0113/2567a606e57ab889c7b7637fa068d475 to your computer and use it in GitHub Desktop.
flutter_isolate_spawn_only_receive
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