import 'dart:isolate';
String mainIsolate = '';
String newIsolate = '';
String get isMainIsolate =>
(mainIsolate == Isolate.current.hashCode.toString()) ? 'π΄' : 'π΅';
void main() async {
mainIsolate = Isolate.current.hashCode.toString();
print('λ©μΈ Isolate μμ');
ReceivePort receivePort = ReceivePort();
await Isolate.spawn(heavyTask, receivePort.sendPort);
receivePort.listen(
(message) {
// 리μ€λ λμμ λ©μΈ Isolateμμ λμνλ€
print('$isMainIsolate 리μ€λ λμ');
print('$isMainIsolate λ°μ λ©μμ§: $message');
print('$isMainIsolate μ’
λ£: ${Isolate.current.hashCode}');
},
);
}
void heavyTask(SendPort port) {
// heavyTask ν¨μλ μλ‘μ΄ Isolateμμ λμνλ€
print('$isMainIsolate μ Isolate μμ: ${Isolate.current.hashCode}');
newIsolate = Isolate.current.hashCode.toString();
port.send('λ¬΄κ±°μ΄ μμ
μ΄ μλ£λμμ΅λλ€ :)');
}
Last active
February 27, 2024 04:42
-
-
Save kipsong133/fdc4a3d61600cdadc0d0130d0b1d5638 to your computer and use it in GitHub Desktop.
flutter_isolate_example_1.dart
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment