Skip to content

Commit

Permalink
Wait for engine initialization before starting analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Yichuan Shen committed Nov 6, 2018
1 parent 2d39f31 commit 96d6945
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.

**Fixed**

* Fix Sabaki incorrectly saying no analysis capable engine is attached when engine hasn't initialized yet
* Fix engine synchronization not working when engine has been suspended
* Fix analysis heatmap disappearing when Leela Zero reaches maximum playouts
* Fix board rendering issues
Expand Down
12 changes: 12 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,18 @@ class App extends Component {
let color = currentPlayer > 0 ? 'B' : 'W'
let controllerIndices = currentPlayer > 0 ? [0, 1] : [1, 0]

if (this.attachedEngineSyncers.some(syncer => syncer && !syncer.initialized)) {
this.setBusy(true)

await Promise.all(this.attachedEngineSyncers.map(syncer =>
syncer && new Promise(resolve => {
syncer.once('engine-initialized', resolve)
})
))

this.setBusy(false)
}

let engineIndex = controllerIndices.find(i =>
this.attachedEngineSyncers[i] != null
&& this.state.engineCommands[i] != null
Expand Down
10 changes: 9 additions & 1 deletion src/modules/enginesyncer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const EventEmitter = require('events')
const {dirname, resolve} = require('path')
const gtp = require('@sabaki/gtp')
const sgf = require('@sabaki/sgf')
Expand All @@ -23,11 +24,14 @@ function coord2vertex(coord, size) {
return [x, y]
}

class EngineSyncer {
class EngineSyncer extends EventEmitter {
constructor(engine) {
super()

let {path, args, commands} = engine

this.engine = engine
this.initialized = false
this.commands = []
this.state = JSON.parse(defaultStateJSON)

Expand All @@ -41,6 +45,9 @@ class EngineSyncer {
this.controller.sendCommand({name: 'protocol_version'})
this.controller.sendCommand({name: 'list_commands'}).then(response => {
this.commands = response.content.split('\n')
}).then(() => {
this.initialized = true
this.emit('engine-initialized')
})

if (commands == null || commands.trim() === '') return
Expand All @@ -51,6 +58,7 @@ class EngineSyncer {
})

this.controller.on('stopped', () => {
this.initialized = false
this.state = JSON.parse(defaultStateJSON)
})

Expand Down

0 comments on commit 96d6945

Please sign in to comment.