Fix race conditions

This commit is contained in:
yflory 2025-02-05 18:19:44 +01:00
parent c9898b575d
commit 43fd606b2f
2 changed files with 7 additions and 3 deletions

View File

@ -89,7 +89,9 @@ const factory = (ApiConfig = {}, Sortify, UserObject, ProxyManager,
var s = getStore(teamId);
if (!s) { return void cb({ error: 'ENOTFOUND' }); }
nThen(function (waitFor) {
Realtime.whenRealtimeSyncs(s.realtime, waitFor());
if (s.realtime) {
Realtime.whenRealtimeSyncs(s.realtime, waitFor());
}
if (!s.id && s.drive?.realtime) {
Realtime.whenRealtimeSyncs(s.drive.realtime, waitFor());
}
@ -2722,7 +2724,8 @@ const factory = (ApiConfig = {}, Sortify, UserObject, ProxyManager,
});
};
var onCacheReady = function (clientId, cb) {
var onCacheReady = function (clientId, _cb) {
const cb = Util.mkAsync(_cb);
var proxy = store.proxy;
var drive = store.drive;
if (store.manager) { return void cb(); }
@ -3215,7 +3218,7 @@ const factory = (ApiConfig = {}, Sortify, UserObject, ProxyManager,
}
if (requires === 'drive') {
loadDrive(clientId, data, ret => {
return void loadDrive(clientId, data, ret => {
cb(ret);
startCacheModules(clientId, ret, onInit);
}, ret => {

View File

@ -65,6 +65,7 @@ const init = (config) => {
returned.anonHash = Hash.getEditHashFromKeys(secret);
}
}).on('cacheready', function (info) {
store.realtime = info.realtime; // XXX move to account
store.offline = true; // XXX move to account
store.networkPromise = info.networkPromise;
store.cacheReturned = returned; // XXX move to account