Skip to content

Commit

Permalink
fix: prevent destory when replicating or save
Browse files Browse the repository at this point in the history
  • Loading branch information
oknoorap committed Dec 13, 2020
1 parent 15fa947 commit 33bdb05
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ml/libs/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Agent {
predictMemory: PredictMemory = {};
bestActionMemory: [Action, string][] = [];
inputSize: number = 59;
isReplicating: boolean = false;
isSaving: boolean = false;

// For spinner purpose
spinner: Spinner;
Expand Down Expand Up @@ -165,16 +167,22 @@ class Agent {
* Save model to model's directory
*/
async saveModel(model: LayersModel) {
this.isSaving = true;
const modelfolder = <string>this.dataPaths("models", model.name);
mkdirp.sync(modelfolder);
await model.save(`file://${modelfolder}`);
this.loading(`Model ${model.name} saved!`);
this.isSaving = false;
}

/**
* Remove models from list
*/
async destroyModel(model: LayersModel) {
if (this.isReplicating || this.isSaving) {
return;
}

const modelIndex = this.models.findIndex(
(item) => item.name === model.name
);
Expand Down Expand Up @@ -281,6 +289,7 @@ class Agent {
* and the quota of modelsNumber was being removed
*/
async replicate() {
this.isReplicating = true;
let count = 0;

for (let i = 0; i < this.modelsNumber; i++) {
Expand All @@ -297,6 +306,7 @@ class Agent {
}

this.loading(`Replicating models`)?.succeed();
this.isReplicating = false;
}

/**
Expand Down

0 comments on commit 33bdb05

Please sign in to comment.