Skip to content

Commit

Permalink
removed the unnecessary lock and added testing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
danielweck committed Nov 27, 2024
1 parent 59729d4 commit d4b7564
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/main/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ const closeProcessLock = (() => {
};
})();

const createStoreProcessLock = (() => {
let lock = false;

return {
get isLock() {
return lock;
},
lock: () => lock = true,
release: () => lock = false,
};
})();
// const createStoreProcessLock = (() => {
// let lock = false;

// return {
// get isLock() {
// return lock;
// },
// lock: () => lock = true,
// release: () => lock = false,
// };
// })();

//
// Depedency Injection
Expand All @@ -181,17 +181,30 @@ const container = new Container();


const getStorePromiseFn = async () => {
createStoreProcessLock.lock();
// createStoreProcessLock.lock();

debug("initStore");
const [store, sagaMiddleware] = await initStore();

// to test concurrent launch (one interactive app with lock, the other CLI)
// npm run start:dev (then close app, this is just to compile main.js)
// .. then launch 2 instances concurrently:
// npm run start:dev:main:electron -- opds Gallica "http://gallica.bnf.fr/opds" &
// npm run start:dev:main:electron &
// ...or the other way around:
// npm run start:dev:main:electron &
// npm run start:dev:main:electron -- opds Gallica "http://gallica.bnf.fr/opds" &
//
// to test long-running store initialisation:
// await new Promise((res) => setTimeout(() => res(undefined), 3*1000));

debug("store loaded");

container.bind<Store<RootState>>(diSymbolTable.store).toConstantValue(store);
container.bind<SagaMiddleware>(diSymbolTable["saga-middleware"]).toConstantValue(sagaMiddleware);
debug("container store and saga binded");

createStoreProcessLock.release();
// createStoreProcessLock.release();

try {
const state = diMainGet("store").getState();
Expand All @@ -213,14 +226,16 @@ const createStoreFromDi = async () => {
return _store;
}

if (createStoreProcessLock.isLock) {
// if (createStoreProcessLock.isLock) {

// return promise store
if (!getStorePromise) throw new Error("not reachable !!!");
return getStorePromise;
}
// // return promise store
// if (!getStorePromise) throw new Error("not reachable !!!");
// return getStorePromise;
// }

getStorePromise = getStorePromiseFn();
if (!getStorePromise) {
getStorePromise = getStorePromiseFn();
}

return getStorePromise;
};
Expand Down

0 comments on commit d4b7564

Please sign in to comment.