Created
October 8, 2019 06:37
-
-
Save Palatnyi/d2c3a795424c276e787179fa68d3bc4c to your computer and use it in GitHub Desktop.
This file contains 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: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