Работа над WebWorker и DbCreator

This commit is contained in:
Book Pauk
2022-08-17 01:17:14 +07:00
parent 425fdf607d
commit a0f701123d
4 changed files with 127 additions and 0 deletions

50
server/core/WebWorker.js Normal file
View File

@@ -0,0 +1,50 @@
const WorkerState = require('./WorkerState');
//server states:
const ssNormal = 'normal';
const ssDbLoading = 'db_loading';
//singleton
let instance = null;
class WebWorker {
constructor(config) {
if (!instance) {
this.config = config;
this.workerState = new WorkerState();
this.wState = this.workerState.getControl('server_state');
this.myState = '';
this.loadOrCreateDb();//no await
instance = this;
}
return instance;
}
checkMyState() {
if (this.myState != ssNormal)
throw new Error('server_busy');
}
setMyState(newState) {
this.myState = newState;
this.wState.set({state: newState});
}
async loadOrCreateDb() {
this.setMyState(ssDbLoading);
try {
//
} catch (e) {
//
} finally {
this.setMyState(ssNormal);
}
}
}
module.exports = WebWorker;