fix race condition in resetting data, fixes #506

This commit is contained in:
Garrett Robinson 2014-04-23 17:30:10 -07:00
Родитель 51f4903fdd
Коммит 5631f3f1c9
2 изменённых файлов: 7 добавлений и 9 удалений

Просмотреть файл

@ -30,7 +30,7 @@ aggregate.edgemap = {};
function resetData() {
console.log('aggregate::resetData');
aggregate.getBlockedDomains().filter(function (domain) {
aggregate.getBlockedDomains().forEach(function (domain) {
console.log("deleting", domain);
delete userSettings[domain];
});
@ -48,13 +48,6 @@ aggregate.on('reset', resetData);
aggregate.getBlockedDomains = function () {
return Object.keys(userSettings).filter(function (domain) {
// ignore domains already known
var nodes = aggregate.nodes;
for (var i = nodes.length - 1; i >= 0; i--) {
if (nodes[i].name == domain) {
return false;
}
}
return userSettings[domain] == 'block';
});
}

Просмотреть файл

@ -156,7 +156,12 @@ document.querySelector('.reset-data').addEventListener('click', function () {
allConnections = [];
global.self.port.emit('reset');
aggregate.emit('reset');
location.reload(); // reload page
// WARNING: this is a race condition. Since the event emitters are
// async, we were running into the situation where the page was reloaded
// before aggregate::resetData was finished, resulting in #506
//
// TODO: using a short timeout for now, would be better to use a Promise
setTimeout(500, function () { location.reload(); /* reload page */ });
}
});
});