Change: make prefs.set return a promise

This commit is contained in:
eight 2019-09-30 18:35:35 +08:00
parent 4666fe493a
commit a051e21ce4

View File

@ -210,10 +210,10 @@ const prefs = (() => {
} }
values[key] = value; values[key] = value;
emitChange(key, value); emitChange(key, value);
if (synced || timer) { if (!synced && !timer) {
return; timer = syncPrefsLater();
} }
timer = setTimeout(syncPrefs); return timer;
} }
function emitChange(key, value) { function emitChange(key, value) {
@ -230,10 +230,14 @@ const prefs = (() => {
} }
} }
function syncPrefs() { function syncPrefsLater() {
// FIXME: we always set the entire object? Ideally, this should only use `changes`. return new Promise((resolve, reject) => {
chrome.storage.sync.set({settings: values}); setTimeout(() => {
timer = null; timer = null;
chrome.storage.sync.set({settings: values})
.then(resolve, reject);
});
});
} }
function equal(a, b) { function equal(a, b) {