I need to wait for the necessary changes in the object to finish the function and return the result to the caller. But I could not think of anything better than using "setInterval". I think I'm doing something wrong.
async checkLockBox ({ state, dispatch, commit }, lockBox) {
if (lockBox.layers === 0) {
commit('lockBox', null);
return lockBox.result;
}
await commit('lockBox', lockBox);
return new Promise((resolve) => {
setInterval(async () => {
if (state.lockBox !== null) {
if (state.lockBox.layers === 0) {
await resolve(state.lockBox.result);
await commit('lockBox', null);
}
}
}, 100);
});
},