1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-05 18:32:30 +01:00

Use async/await instead of chained thens

This commit is contained in:
Raymond Hill 2019-09-21 19:48:02 -04:00
parent 3568ccdd33
commit 8c47fa1a3e
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -1045,52 +1045,63 @@
})
),
µb.redirectEngine.toSelfie('selfie/redirectEngine'),
µb.staticExtFilteringEngine.toSelfie('selfie/staticExtFilteringEngine'),
µb.staticNetFilteringEngine.toSelfie('selfie/staticNetFilteringEngine'),
µb.staticExtFilteringEngine.toSelfie(
'selfie/staticExtFilteringEngine'
),
µb.staticNetFilteringEngine.toSelfie(
'selfie/staticNetFilteringEngine'
),
]);
µb.lz4Codec.relinquish();
};
const loadMain = async function() {
const details = await µb.assets.get('selfie/main');
if (
details instanceof Object === false ||
typeof details.content !== 'string' ||
details.content === ''
) {
return false;
}
let selfie;
try {
selfie = JSON.parse(details.content);
} catch(ex) {
}
if (
selfie instanceof Object === false ||
selfie.magic !== µb.systemSettings.selfieMagic
) {
return false;
}
µb.availableFilterLists = selfie.availableFilterLists;
return true;
};
const load = async function() {
if ( destroyTimer !== undefined ) {
return Promise.resolve(false);
return false;
}
return Promise.all([
µb.assets.get('selfie/main').then(details => {
if (
details instanceof Object === false ||
typeof details.content !== 'string' ||
details.content === ''
) {
return false;
}
let selfie;
try {
selfie = JSON.parse(details.content);
} catch(ex) {
}
if (
selfie instanceof Object === false ||
selfie.magic !== µb.systemSettings.selfieMagic
) {
return false;
}
µb.availableFilterLists = selfie.availableFilterLists;
return true;
}),
µb.redirectEngine.fromSelfie('selfie/redirectEngine'),
µb.staticExtFilteringEngine.fromSelfie('selfie/staticExtFilteringEngine'),
µb.staticNetFilteringEngine.fromSelfie('selfie/staticNetFilteringEngine'),
]).then(results => {
if ( results.reduce((acc, v) => acc && v, true) ) {
try {
const results = await Promise.all([
loadMain(),
µb.redirectEngine.fromSelfie('selfie/redirectEngine'),
µb.staticExtFilteringEngine.fromSelfie(
'selfie/staticExtFilteringEngine'
),
µb.staticNetFilteringEngine.fromSelfie(
'selfie/staticNetFilteringEngine'
),
]);
if ( results.every(v => v) ) {
return µb.loadRedirectResources();
}
return false;
}).catch(reason => {
}
catch (reason) {
log.info(reason);
return false;
});
}
return false;
};
const destroy = function() {