@@ -49,12 +49,13 @@ export class AsyncStorageTurboModule extends TurboModule {
49
49
* Given an array of keys, this returns a map of (key, value) pairs for the keys found, and
50
50
* (key, null) for the keys that haven't been found.
51
51
*/
52
- multiGet ( keys : string [ ] , callback : ( error ?: Object , result ?: [ string , string ] [ ] | null ) => void ) {
52
+ multiGet ( keys : string [ ] , callback : ( error ?: Object , result ?: [ string , string ] [ ] | null ) => void ) : Promise < void > {
53
53
Logger . debug ( CommonConstants . TAG , `Module multiGet() Call!` ) ;
54
54
this . runMultiGet ( keys ) . then ( ( result ) => { callback ( result [ 0 ] , result [ 1 ] ) } ) . catch ( ( e : Error ) => {
55
55
Logger . debug ( CommonConstants . TAG , `Module multiGet() Call Fail!${ e . message } ` ) ;
56
56
} )
57
57
Logger . debug ( CommonConstants . TAG , `Module multiGet() End!` ) ;
58
+ return Promise . resolve ( ) ;
58
59
}
59
60
60
61
async runMultiGet ( keys : string [ ] ) : Promise < [ Object , [ string , string ] [ ] | null ] > {
@@ -129,12 +130,13 @@ export class AsyncStorageTurboModule extends TurboModule {
129
130
* return AsyncLocalStorageFailure, but all other pairs will have been inserted.
130
131
* The insertion will replace conflicting (key, value) pairs.
131
132
*/
132
- multiSet ( keyValueArray : [ string , string ] [ ] , callback : ( error ?: Object ) => void ) {
133
+ multiSet ( keyValueArray : [ string , string ] [ ] , callback : ( error ?: Object ) => void ) : Promise < void > {
133
134
Logger . debug ( CommonConstants . TAG , `Module multiSet() Call!` ) ;
134
135
this . runMultiSet ( keyValueArray ) . then ( ( error ) => { callback ( error ) } ) . catch ( ( e : Error ) => {
135
136
Logger . debug ( CommonConstants . TAG , `Module multiSet() Call Fail!${ e . message } ` ) ;
136
137
} )
137
138
Logger . debug ( CommonConstants . TAG , `Module multiSet() End!` ) ;
139
+ return Promise . resolve ( ) ;
138
140
}
139
141
140
142
async runMultiSet ( keyValueArray : [ string , string ] [ ] , hasError = false ) : Promise < Object > {
@@ -200,7 +202,7 @@ export class AsyncStorageTurboModule extends TurboModule {
200
202
}
201
203
}
202
204
}
203
- if ( error !== null ) {
205
+ if ( error !== null ) {
204
206
return error ;
205
207
} else {
206
208
return null ;
@@ -210,12 +212,13 @@ export class AsyncStorageTurboModule extends TurboModule {
210
212
/**
211
213
* Removes all rows of the keys given.
212
214
*/
213
- multiRemove ( keys : string [ ] , callback : ( error ?:Object ) => void ) {
215
+ multiRemove ( keys : string [ ] , callback : ( error ?: Object ) => void ) : Promise < void > {
214
216
Logger . debug ( CommonConstants . TAG , `Module multiRemove() Call!` ) ;
215
- this . runMultiRemove ( keys ) . then ( ( error ) => { callback ( error ) } ) . catch ( ( e :Error ) => {
217
+ this . runMultiRemove ( keys ) . then ( ( error ) => { callback ( error ) } ) . catch ( ( e : Error ) => {
216
218
Logger . debug ( CommonConstants . TAG , `Module multiRemove() Call Fail!${ e . message } ` ) ;
217
219
} )
218
220
Logger . debug ( CommonConstants . TAG , `Module multiRemove() End!` ) ;
221
+ return Promise . resolve ( ) ;
219
222
}
220
223
221
224
async runMultiRemove ( keys : string [ ] ) : Promise < Object > {
@@ -237,7 +240,7 @@ export class AsyncStorageTurboModule extends TurboModule {
237
240
238
241
async asyncMultiRemove ( keys : string [ ] ) : Promise < Object > {
239
242
Logger . debug ( CommonConstants . TAG , `ModuleSub asyncMultiRemove() Call!` ) ;
240
- if ( keys . length === 0 ) {
243
+ if ( keys . length === 0 ) {
241
244
return null ;
242
245
}
243
246
if ( ! await this . table . ensureDatabase ( this . ctx . uiAbilityContext ) ) {
@@ -269,12 +272,13 @@ export class AsyncStorageTurboModule extends TurboModule {
269
272
* Given an array of (key, value) pairs, this will merge the given values with the stored values
270
273
* of the given keys, if they exist.
271
274
*/
272
- multiMerge ( keyValueArray : [ string , string ] [ ] , callback : ( error ?: Object ) => void ) {
275
+ multiMerge ( keyValueArray : [ string , string ] [ ] , callback : ( error ?: Object ) => void ) : Promise < void > {
273
276
Logger . debug ( CommonConstants . TAG , `Module multiMerge() Call!` ) ;
274
- this . runMultiMerge ( keyValueArray ) . then ( ( error ) => { callback ( error ) } ) . catch ( ( e :Error ) => {
277
+ this . runMultiMerge ( keyValueArray ) . then ( ( error ) => { callback ( error ) } ) . catch ( ( e : Error ) => {
275
278
Logger . debug ( CommonConstants . TAG , `Module multiMerge() Call Fail!${ e . message } ` ) ;
276
279
} )
277
280
Logger . debug ( CommonConstants . TAG , `Module multiMerge() End!` ) ;
281
+ return Promise . resolve ( ) ;
278
282
}
279
283
280
284
async runMultiMerge ( keyValueArray : [ string , string ] [ ] ) : Promise < Object > {
@@ -314,16 +318,16 @@ export class AsyncStorageTurboModule extends TurboModule {
314
318
error = AsyncStorageErrorUtil . getInvalidValueError ( null )
315
319
return error ;
316
320
}
317
- if ( ! await AsyncLocalStorageUtil . mergeImpl ( this . table . rdbStore , keyValueArray [ idx ] [ 0 ] , keyValueArray [ idx ] [ 1 ] ) ) {
321
+ if ( ! await AsyncLocalStorageUtil . mergeImpl ( this . table . rdbStore , keyValueArray [ idx ] [ 0 ] , keyValueArray [ idx ] [ 1 ] ) ) {
318
322
error = AsyncStorageErrorUtil . getDBError ( null )
319
323
return error ;
320
324
}
321
325
}
322
326
} catch ( e ) {
323
327
Logger . warn ( CommonConstants . TAG , e . message ) ;
324
328
error = AsyncStorageErrorUtil . getError ( null , e . message ) ;
325
- }
326
- if ( error != null ) {
329
+ }
330
+ if ( error != null ) {
327
331
return error ;
328
332
} else {
329
333
return null ;
@@ -333,12 +337,13 @@ export class AsyncStorageTurboModule extends TurboModule {
333
337
/**
334
338
* Clears the database.
335
339
*/
336
- clear ( callback : ( error ?: Object ) => void ) {
340
+ clear ( callback : ( error ?: Object ) => void ) : Promise < void > {
337
341
Logger . debug ( CommonConstants . TAG , `Module clear() Call!` ) ;
338
- this . runClear ( ) . then ( ( error ) => { callback ( error ) } ) . catch ( ( e :Error ) => {
342
+ this . runClear ( ) . then ( ( error ) => { callback ( error ) } ) . catch ( ( e : Error ) => {
339
343
Logger . debug ( CommonConstants . TAG , `Module clear() Call Fail!${ e . message } ` ) ;
340
344
} )
341
345
Logger . debug ( CommonConstants . TAG , `Module clear() End!` ) ;
346
+ return Promise . resolve ( ) ;
342
347
}
343
348
344
349
async runClear ( ) : Promise < Object > {
@@ -375,12 +380,13 @@ export class AsyncStorageTurboModule extends TurboModule {
375
380
/**
376
381
* Returns an array with all keys from the database.
377
382
*/
378
- getAllKeys ( callback : ( error ?: Object , result ?: string [ ] | null ) => void ) {
383
+ getAllKeys ( callback : ( error ?: Object , result ?: string [ ] | null ) => void ) : Promise < void > {
379
384
Logger . debug ( CommonConstants . TAG , `Module getAllKeys() Call!` ) ;
380
- this . runGetAllKeys ( ) . then ( ( result ) => { callback ( result [ 0 ] , result [ 1 ] ) } ) . catch ( ( e :Error ) => {
385
+ this . runGetAllKeys ( ) . then ( ( result ) => { callback ( result [ 0 ] , result [ 1 ] ) } ) . catch ( ( e : Error ) => {
381
386
Logger . debug ( CommonConstants . TAG , `Module getAllKeys() Call Fail!${ e . message } ` ) ;
382
387
} )
383
388
Logger . debug ( CommonConstants . TAG , `Module getAllKeys() End!` ) ;
389
+ return Promise . resolve ( ) ;
384
390
}
385
391
386
392
async runGetAllKeys ( ) : Promise < [ Object , string [ ] | null ] > {
@@ -410,14 +416,14 @@ export class AsyncStorageTurboModule extends TurboModule {
410
416
predicates . isNotNull ( ReactDatabaseSupplier . KEY_COLUMN ) ;
411
417
let cursor = await this . table . rdbStore . query ( predicates ) ;
412
418
try {
413
- if ( cursor . goToFirstRow ( ) ) {
419
+ if ( cursor . goToFirstRow ( ) ) {
414
420
do {
415
421
data . push ( cursor . getString ( cursor . getColumnIndex ( 'KEY' ) ) ) ;
416
422
} while ( cursor . goToNextRow ( ) )
417
423
}
418
424
} catch ( e ) {
419
425
Logger . warn ( CommonConstants . TAG , `Module GetAllKeys() error: ${ e . message } ` ) ;
420
- return [ AsyncStorageErrorUtil . getError ( null , e . message ) , null ] ;
426
+ return [ AsyncStorageErrorUtil . getError ( null , e . message ) , null ] ;
421
427
} finally {
422
428
cursor . close ( ) ;
423
429
}
0 commit comments