flutter: devmode: No need to throw exception when shutdown

Because frontend send 'shutdown' to engine when dispose.
Detect timeout only when send go and engine not receive shutdown.
This commit is contained in:
Calcitem 2021-05-16 09:52:43 +08:00
parent ab86323b4a
commit cf44c3f57a
1 changed files with 5 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import 'engine.dart';
class NativeEngine extends Engine {
static const platform = const MethodChannel('com.calcitem.sanmill/engine');
bool isActive = false;
Future<void> startup() async {
await platform.invokeMethod('startup');
@ -43,6 +44,7 @@ class NativeEngine extends Engine {
}
Future<void> shutdown() async {
isActive = false;
await platform.invokeMethod('shutdown');
}
@ -60,6 +62,7 @@ class NativeEngine extends Engine {
await send(getPositionFen(position!));
await send('go');
isActive = true;
final response = await waitResponse(['bestmove', 'nobestmove']);
@ -92,7 +95,7 @@ class NativeEngine extends Engine {
if (times > timeLimit) {
print("Timeout. sleep = $sleep, times = $times");
if (Config.developerMode) {
if (Config.developerMode && isActive) {
throw ("Exception: waitResponse timeout.");
}
return '';
@ -117,6 +120,7 @@ class NativeEngine extends Engine {
}
Future<void> stopSearching() async {
isActive = false;
await send('stop');
}