1+ import { asError } from "../../common/helpers-pure" ;
2+
13/**
24 * A cached mapping from strings to value of type U.
35 */
@@ -7,7 +9,7 @@ export class CachedOperation<U> {
79 private readonly lru : string [ ] ;
810 private readonly inProgressCallbacks : Map <
911 string ,
10- Array < [ ( u : U ) => void , ( reason ?: any ) => void ] >
12+ Array < [ ( u : U ) => void , ( reason ?: Error ) => void ] >
1113 > ;
1214
1315 constructor (
@@ -18,7 +20,7 @@ export class CachedOperation<U> {
1820 this . lru = [ ] ;
1921 this . inProgressCallbacks = new Map <
2022 string ,
21- Array < [ ( u : U ) => void , ( reason ?: any ) => void ] >
23+ Array < [ ( u : U ) => void , ( reason ?: Error ) => void ] >
2224 > ( ) ;
2325 this . cached = new Map < string , U > ( ) ;
2426 }
@@ -46,7 +48,7 @@ export class CachedOperation<U> {
4648 }
4749
4850 // Otherwise compute the new value, but leave a callback to allow sharing work
49- const callbacks : Array < [ ( u : U ) => void , ( reason ?: any ) => void ] > = [ ] ;
51+ const callbacks : Array < [ ( u : U ) => void , ( reason ?: Error ) => void ] > = [ ] ;
5052 this . inProgressCallbacks . set ( t , callbacks ) ;
5153 try {
5254 const result = await this . operation ( t , ...args ) ;
@@ -61,7 +63,7 @@ export class CachedOperation<U> {
6163 return result ;
6264 } catch ( e ) {
6365 // Rethrow error on all callbacks
64- callbacks . forEach ( ( f ) => f [ 1 ] ( e ) ) ;
66+ callbacks . forEach ( ( f ) => f [ 1 ] ( asError ( e ) ) ) ;
6567 throw e ;
6668 } finally {
6769 this . inProgressCallbacks . delete ( t ) ;
0 commit comments