File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 11/** Provides lazy initialization support */
22export class Lazy < T > {
3+ private _evaluated : boolean = false ;
4+ get evaluated ( ) : boolean {
5+ return this . _evaluated ;
6+ }
7+
8+ private _exception : Error | undefined ;
39 private _value ?: T ;
4- private _initialized : boolean = false ;
510
611 /**
712 * Creates a new instance of Lazy<T> that uses the specified initialization function.
@@ -11,11 +16,19 @@ export class Lazy<T> {
1116
1217 /** Gets the lazily initialized value of the current Lazy<T> instance */
1318 get value ( ) : T {
14- if ( ! this . _initialized ) {
15- this . _value = this . valueProvider ( ) ;
16- this . _initialized = true ;
19+ if ( ! this . _evaluated ) {
20+ try {
21+ this . _value = this . valueProvider ( ) ;
22+ } catch ( ex ) {
23+ this . _exception = ex ;
24+ throw ex ;
25+ } finally {
26+ this . _evaluated = true ;
27+ }
1728 }
1829
30+ if ( this . _exception ) throw this . _exception ;
31+
1932 return this . _value ! ;
2033 }
2134}
You can’t perform that action at this time.
0 commit comments