Skip to content

Instantly share code, notes, and snippets.

@Palatnyi
Created October 8, 2019 06:37
Show Gist options
  • Save Palatnyi/d2c3a795424c276e787179fa68d3bc4c to your computer and use it in GitHub Desktop.
Save Palatnyi/d2c3a795424c276e787179fa68d3bc4c to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
import 'package:random_string/random_string.dart';
Isolate isolate;
main() {
print("running dart program");
createNewIsolate();
}
void createNewIsolate() {
ReceivePort receivePort = ReceivePort();
Isolate.spawn(isolateMain, receivePort.sendPort)
.then((_isolate) {
isolate = _isolate;
print('isolate: $isolate');
receivePort.listen((messages) {
print('new message from ISOLATE $messages');
});
});
}
void isolateMain(SendPort sendPort) {
int i = 0;
Timer.periodic(new Duration(seconds: 2), (Timer t) {
if(i == 5) exit(0);
i += 1;
sendPort.send('RANDOM STRING: ${randomString(10)}; RANDOM INTEGER: ${randomNumeric(10)}');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment