Skip to content

Instantly share code, notes, and snippets.

@lmzach09
Last active August 6, 2019 02:03
Show Gist options
  • Save lmzach09/e4900dc76f5e39bc29b26a6939284ce6 to your computer and use it in GitHub Desktop.
Save lmzach09/e4900dc76f5e39bc29b26a6939284ce6 to your computer and use it in GitHub Desktop.
This is a function that a Dart Isolate can execute. It will listen for messages from the main thread and also send messages to the main thread.
void myIsolate(SendPort isolateToMainStream) {
ReceivePort mainToIsolateStream = ReceivePort();
isolateToMainStream.send(mainToIsolateStream.sendPort);
mainToIsolateStream.listen((data) {
print('[mainToIsolateStream] $data');
});
isolateToMainStream.send('This is from myIsolate()');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment