It seems that if a preference is changed by the user then after theia restart the change happens via event:
protected async initializeProviders(): Promise<void> {
try {
for (const scope of PreferenceScope.getScopes()) {
const provider = this.providerProvider(scope);
this.preferenceProviders.set(scope, provider);
this.toDispose.push(provider.onDidPreferencesChanged(changes =>
this.reconcilePreferences(changes)
));
await provider.ready;
}
this._ready.resolve();
} catch (e) {
this._ready.reject(e);
}
}
Question is what is the right way to read the correct value on theia startup as there a race condition between ready and change events.
[original thread by amiramw]
There is a fix sketched out if you want to take a stab at it.
otherwise, what are you trying to achieve? Maybe I can suggest a workaround, having looked at this code closely recently.
[amiramw]
I have a flow on onStart that pulls a value from preference
[amiramw]
Since preference providers update the preference on AbstractResourcePreferenceProvider.init there is a race condition
[amiramw]
I wonder if this._ready.resolve() should not be after this.readPreferences() and then once the preference service is ready it will mean that all initial providers updated their values already
I wonder if this._ready.resolve() should not be after this.readPreferences()
Yes it should (:-)), but unfortunately, that deadlocks because reading the preferences through an editor model reads preferences and that will wait for _ready() Hence my proposal to read preferences through a normal file read and only moving to a model when it’s needed.