diff --git a/ui/ceval/src/engines/externalEngine.ts b/ui/ceval/src/engines/externalEngine.ts index 862dc2f489c5..8625fc309f32 100644 --- a/ui/ceval/src/engines/externalEngine.ts +++ b/ui/ceval/src/engines/externalEngine.ts @@ -1,6 +1,7 @@ import { Work, ExternalEngineInfo, CevalEngine, CevalState } from '../types'; import { randomToken } from 'common/random'; import { readNdJson } from 'common/ndjson'; +import throttle from 'common/throttle'; interface ExternalEngineOutput { time: number; @@ -35,10 +36,13 @@ export class ExternalEngine implements CevalEngine { start(work: Work) { this.stop(); this.state = CevalState.Loading; + this.process(work); + } + process = throttle(700, work => { this.req = new AbortController(); this.analyse(work, this.req.signal); - } + }); private async analyse(work: Work, signal: AbortSignal): Promise { try { @@ -57,7 +61,7 @@ export class ExternalEngine implements CevalEngine { sessionId: this.sessionId, threads: work.threads, hash: work.hashSize || 16, - infinite: true, // TODO WTF + movetime: work.searchMs === Number.POSITIVE_INFINITY ? 24 * 3600 * 1000 : work.searchMs, multiPv: work.multiPv, variant: work.variant, initialFen: work.initialFen, @@ -65,7 +69,6 @@ export class ExternalEngine implements CevalEngine { }, }), }); - await readNdJson(res, line => { this.state = CevalState.Computing; work.emit({