I've been playing around with Dart Isolates and have run into a problem using the isolate.pause();
function.
import 'dart:io';
import 'dart:isolate';
main(){
ReceivePort receivePort = new ReceivePort();
Isolate.spawn(isolateEntryPoint, receivePort.sendPort).then((isolate){
isolate.pause(isolate.pauseCapability);
});
}
void isolateEntryPoint(SendPort sendPort){
while(true){
print("isolate is running");
sleep(new Duration(seconds: 2));
}
}
In my example the isolate basically just prints something out every 2 seconds.
From what I read on the docs, my understanding is that the above code should:
- Spawn an isolate
- Promptly pause that isolate
But it's not working, the isolate is still running and printing "isolate is running" every 2 seconds even after I tell it to pause.
I'm aware that you can start an isolate in a paused state by passing in the paused: true
optional parameter:
Isolate.spawn(isolateEntryPoint, receivePort, paused: true)...
. Ultimately however I would like to be able to pause the isolate at any point, not just right off the bat.
The only documentation I could find about using this was on the official dart docs, so it's possible I'm using the isolate.pause()
function incorrectly. But either way a code example demonstrating the correct usage of this function would be greatly appreciated.