How to terminate a long running isolate #2

Issue

I am trying to understand how I shall port my Java chess engine to dart.

So I have understood that I should use an Isolates to run my engine in parallell with the GUI but how can I force the engine to terminate the search.

In java I just set some boolean that where shared between the engine thread and the gui thread.

Answer I got:

You should send a message to the isolate, telling it to stop. You can simply do something like:

port.send(‘STOP’);

My request

Thanks for the clarification. What I don’t understand is that if the chess engine isolate is busy due to a port.send(‘THINK’) command how can it respond to a port.send(‘STOP’) command

Solution

The new API will contain a

isolate.kill(loopForever ? Isolate.IMMEDIATE : Isolate.AS_EVENT); 

See https://code.google.com/p/dart/issues/detail?id=21189#c4 for a full example.

Answered By – Günter Zöchbauer

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *