@@ -47,33 +47,27 @@ const isCSS = a => isProcedural(a) === false && isScriptlet(a) === false;
4747
4848/******************************************************************************/
4949
50- async function flushWrites ( ) {
51- while ( pendingWrites . length !== 0 ) {
52- const promises = pendingWrites ;
53- pendingWrites . length = 0 ;
54- await Promise . all ( promises ) ;
55- }
56- }
57-
5850async function keysFromStorage ( ) {
59- await flushWrites ( ) ;
60- return localKeys ( ) ;
51+ pendingStorageOp = pendingStorageOp . then ( ( ) => localKeys ( ) ) ;
52+ return pendingStorageOp ;
6153}
6254
6355async function readFromStorage ( key ) {
64- await flushWrites ( ) ;
65- return localRead ( key ) ;
56+ pendingStorageOp = pendingStorageOp . then ( ( ) => localRead ( key ) ) ;
57+ return pendingStorageOp ;
6658}
6759
6860async function writeToStorage ( key , value ) {
69- pendingWrites . push ( localWrite ( key , value ) ) ;
61+ pendingStorageOp = pendingStorageOp . then ( ( ) => localWrite ( key , value ) ) ;
62+ return pendingStorageOp ;
7063}
7164
7265async function removeFromStorage ( key ) {
73- pendingWrites . push ( localRemove ( key ) ) ;
66+ pendingStorageOp = pendingStorageOp . then ( ( ) => localRemove ( key ) ) ;
67+ return pendingStorageOp ;
7468}
7569
76- const pendingWrites = [ ] ;
70+ let pendingStorageOp = Promise . resolve ( ) ;
7771
7872/******************************************************************************/
7973
@@ -117,7 +111,7 @@ async function getAllCustomFilterKeys() {
117111export async function getAllCustomFilters ( ) {
118112 const collect = async key => {
119113 const selectors = await readFromStorage ( key ) ;
120- return [ key . slice ( 5 ) , selectors ] ;
114+ return [ key . slice ( 5 ) , selectors ?? [ ] ] ;
121115 } ;
122116 const keys = await getAllCustomFilterKeys ( ) ;
123117 const promises = keys . map ( k => collect ( k ) ) ;
0 commit comments