@@ -396,26 +396,25 @@ const updateAssetSourceRegistry = function(json, silent) {
396396
397397const getAssetSourceRegistry = function ( callback ) {
398398 if ( assetSourceRegistryPromise === undefined ) {
399- assetSourceRegistryPromise = new Promise ( resolve => {
400- // start of executor
401- µBlock . cacheStorage . get ( 'assetSourceRegistry' , bin => {
399+ assetSourceRegistryPromise = µBlock . cacheStorage . get (
400+ 'assetSourceRegistry'
401+ ) . then ( bin => {
402402 if (
403- bin instanceof Object === false ||
404- bin . assetSourceRegistry instanceof Object === false
403+ bin instanceof Object &&
404+ bin . assetSourceRegistry instanceof Object
405405 ) {
406+ assetSourceRegistry = bin . assetSourceRegistry ;
407+ return ;
408+ }
409+ return new Promise ( resolve => {
406410 api . fetchText (
407411 µBlock . assetsBootstrapLocation || 'assets/assets.json' ,
408412 details => {
409413 updateAssetSourceRegistry ( details . content , true ) ;
410414 resolve ( ) ;
411415 }
412416 ) ;
413- return ;
414- }
415- assetSourceRegistry = bin . assetSourceRegistry ;
416- resolve ( ) ;
417- } ) ;
418- // end of executor
417+ } ) ;
419418 } ) ;
420419 }
421420
@@ -451,16 +450,15 @@ let assetCacheRegistry = {};
451450
452451const getAssetCacheRegistry = function ( ) {
453452 if ( assetCacheRegistryPromise === undefined ) {
454- assetCacheRegistryPromise = new Promise ( resolve => {
455- µBlock . cacheStorage . get ( 'assetCacheRegistry' , bin => {
456- if (
457- bin instanceof Object &&
458- bin . assetCacheRegistry instanceof Object
459- ) {
460- assetCacheRegistry = bin . assetCacheRegistry ;
461- }
462- resolve ( ) ;
463- } ) ;
453+ assetCacheRegistryPromise = µBlock . cacheStorage . get (
454+ 'assetCacheRegistry'
455+ ) . then ( bin => {
456+ if (
457+ bin instanceof Object &&
458+ bin . assetCacheRegistry instanceof Object
459+ ) {
460+ assetCacheRegistry = bin . assetCacheRegistry ;
461+ }
464462 } ) ;
465463 }
466464
@@ -509,8 +507,11 @@ const assetCacheRead = function(assetKey, callback) {
509507 reportBack ( bin [ internalKey ] ) ;
510508 } ;
511509
512- getAssetCacheRegistry ( ) . then ( ( ) => {
513- µBlock . cacheStorage . get ( internalKey , onAssetRead ) ;
510+ Promise . all ( [
511+ getAssetCacheRegistry ( ) ,
512+ µBlock . cacheStorage . get ( internalKey ) ,
513+ ] ) . then ( results => {
514+ onAssetRead ( results [ 1 ] ) ;
514515 } ) ;
515516} ;
516517
@@ -537,17 +538,16 @@ const assetCacheWrite = function(assetKey, details, callback) {
537538 entry . remoteURL = details . url ;
538539 }
539540 µBlock . cacheStorage . set (
540- { [ internalKey ] : content } ,
541- details => {
542- if (
543- details instanceof Object &&
544- typeof details . bytesInUse === 'number'
545- ) {
546- entry . byteLength = details . bytesInUse ;
547- }
548- saveAssetCacheRegistry ( true ) ;
541+ { [ internalKey ] : content }
542+ ) . then ( details => {
543+ if (
544+ details instanceof Object &&
545+ typeof details . bytesInUse === 'number'
546+ ) {
547+ entry . byteLength = details . bytesInUse ;
549548 }
550- ) ;
549+ saveAssetCacheRegistry ( true ) ;
550+ } ) ;
551551 const result = { assetKey, content } ;
552552 if ( typeof callback === 'function' ) {
553553 callback ( result ) ;
@@ -556,9 +556,7 @@ const assetCacheWrite = function(assetKey, details, callback) {
556556 fireNotification ( 'after-asset-updated' , result ) ;
557557 } ;
558558
559- getAssetCacheRegistry ( ) . then ( ( ) => {
560- µBlock . cacheStorage . get ( internalKey , onReady ) ;
561- } ) ;
559+ getAssetCacheRegistry ( ) . then ( ( ) => onReady ( ) ) ;
562560} ;
563561
564562const assetCacheRemove = function ( pattern , callback ) {
0 commit comments