@@ -34,7 +34,7 @@ export interface EffectMeta {
34
34
}
35
35
36
36
interface EffectRunner < T > {
37
- version : T
37
+ epoch : T
38
38
execute : ( ) => any
39
39
collect : ( dispose : Disposable ) => void
40
40
getOuterStack : ( ) => string [ ]
@@ -109,7 +109,7 @@ export class Fiber<out C extends Context = Context> {
109
109
}
110
110
111
111
this . _runner = {
112
- version : INACTIVE ,
112
+ epoch : INACTIVE ,
113
113
getOuterStack,
114
114
execute : ( ) => {
115
115
if ( isConstructor ( runtime . callback ) ) {
@@ -151,7 +151,7 @@ export class Fiber<out C extends Context = Context> {
151
151
this . ctx . registry . delete ( runtime . callback )
152
152
}
153
153
}
154
- this . _setVersion ( INACTIVE )
154
+ this . _setEpoch ( INACTIVE )
155
155
await this . await ( )
156
156
}
157
157
} , 'ctx.plugin()' )
@@ -160,7 +160,7 @@ export class Fiber<out C extends Context = Context> {
160
160
this . ctx = this . context = parent
161
161
this . state = FiberState . ACTIVE
162
162
this . _runner = {
163
- version : '' ,
163
+ epoch : '' ,
164
164
getOuterStack,
165
165
execute : ( ) => { } ,
166
166
collect,
@@ -184,7 +184,7 @@ export class Fiber<out C extends Context = Context> {
184
184
}
185
185
186
186
private _execute < T > ( runner : EffectRunner < T > ) {
187
- const version = runner . version
187
+ const oldEpoch = runner . epoch
188
188
return composeError ( ( info ) => {
189
189
const safeCollect = ( dispose : void | Disposable ) => {
190
190
if ( typeof dispose === 'function' ) {
@@ -217,7 +217,7 @@ export class Fiber<out C extends Context = Context> {
217
217
await Promise . resolve ( )
218
218
info . error = new Error ( )
219
219
while ( true ) {
220
- if ( runner . version !== version ) return
220
+ if ( runner . epoch !== oldEpoch ) return
221
221
const result = await iter . next ( )
222
222
safeCollect ( result . value )
223
223
if ( result . done ) return
@@ -253,7 +253,7 @@ export class Fiber<out C extends Context = Context> {
253
253
const meta : EffectMeta = { label, children : [ ] }
254
254
const runner : EffectRunner < boolean > = {
255
255
execute,
256
- version : true ,
256
+ epoch : true ,
257
257
collect : ( dispose ) => {
258
258
disposables . push ( dispose )
259
259
this . _disposables . delete ( dispose )
@@ -276,14 +276,14 @@ export class Fiber<out C extends Context = Context> {
276
276
task ?. catch ( dispose )
277
277
278
278
const wrapper = defineProperty ( ( ) => {
279
- if ( ! runner . version ) return
280
- runner . version = false
279
+ if ( ! runner . epoch ) return
280
+ runner . epoch = false
281
281
return task ? task . then ( dispose ) : dispose ( )
282
282
} , symbols . effect , meta ) as AsyncDisposable
283
283
284
284
const disposeAsync = ( ) => {
285
- if ( ! runner . version ) return
286
- runner . version = false
285
+ if ( ! runner . epoch ) return
286
+ runner . epoch = false
287
287
return dispose ( )
288
288
}
289
289
wrapper . then = async ( onFulfilled , onRejected ) => {
@@ -304,7 +304,7 @@ export class Fiber<out C extends Context = Context> {
304
304
private _getState ( ) {
305
305
if ( this . uid === null ) return FiberState . DISPOSED
306
306
if ( this . _error ) return FiberState . FAILED
307
- if ( this . _runner . version !== INACTIVE ) return FiberState . ACTIVE
307
+ if ( this . _runner . epoch !== INACTIVE ) return FiberState . ACTIVE
308
308
return FiberState . PENDING
309
309
}
310
310
@@ -339,27 +339,27 @@ export class Fiber<out C extends Context = Context> {
339
339
}
340
340
341
341
_refresh ( ) {
342
- let version : string | boolean = false
343
- version = ''
342
+ let epoch : string | boolean = false
343
+ epoch = ''
344
344
for ( const [ name , inject ] of Object . entries ( this . inject ) ) {
345
345
if ( ! inject ! . required ) continue
346
346
const impl = this . _store [ name ]
347
347
if ( ! impl ) {
348
- version = INACTIVE
348
+ epoch = INACTIVE
349
349
break
350
350
}
351
- version += ':' + impl . fiber . uid
351
+ epoch += ':' + impl . fiber . uid
352
352
}
353
- this . _setVersion ( version )
353
+ this . _setEpoch ( epoch )
354
354
}
355
355
356
- private _setVersion ( version : string ) {
357
- const oldVersion = this . _runner . version
358
- if ( version === oldVersion ) return
359
- this . _runner . version = version
356
+ private _setEpoch ( epoch : string ) {
357
+ const oldEpoch = this . _runner . epoch
358
+ if ( epoch === oldEpoch ) return
359
+ this . _runner . epoch = epoch
360
360
if ( this . inertia ) return
361
361
this . _updateState ( ( ) => {
362
- if ( version !== INACTIVE && oldVersion === INACTIVE ) {
362
+ if ( epoch !== INACTIVE && oldEpoch === INACTIVE ) {
363
363
this . inertia = this . _reload ( )
364
364
return FiberState . LOADING
365
365
} else {
@@ -371,18 +371,18 @@ export class Fiber<out C extends Context = Context> {
371
371
372
372
private async _reload ( ) {
373
373
this . store = { ...this . _store }
374
- const version = this . _runner . version
374
+ const oldEpoch = this . _runner . epoch
375
375
try {
376
376
await Promise . resolve ( )
377
377
await this . _execute ( this . _runner )
378
378
} catch ( reason ) {
379
379
// impl guarantees that the error is non-null (?)
380
380
this . context . emit ( this . ctx , 'internal/error' , reason )
381
381
this . _error = reason
382
- this . _runner . version = INACTIVE
382
+ this . _runner . epoch = INACTIVE
383
383
}
384
384
this . _updateState ( ( ) => {
385
- if ( this . _runner . version === version ) {
385
+ if ( this . _runner . epoch === oldEpoch ) {
386
386
this . inertia = undefined
387
387
} else {
388
388
this . inertia = this . _unload ( )
@@ -405,7 +405,7 @@ export class Fiber<out C extends Context = Context> {
405
405
} ) )
406
406
this . store = undefined
407
407
this . _updateState ( ( ) => {
408
- if ( this . _runner . version === INACTIVE ) {
408
+ if ( this . _runner . epoch === INACTIVE ) {
409
409
this . inertia = undefined
410
410
} else {
411
411
this . inertia = this . _reload ( )
@@ -424,7 +424,7 @@ export class Fiber<out C extends Context = Context> {
424
424
425
425
async restart ( ) {
426
426
this . assertActive ( )
427
- this . _setVersion ( INACTIVE )
427
+ this . _setEpoch ( INACTIVE )
428
428
this . _refresh ( )
429
429
await this . await ( )
430
430
}
@@ -437,7 +437,7 @@ export class Fiber<out C extends Context = Context> {
437
437
} catch ( error ) {
438
438
this . context . emit ( 'internal/error' , error )
439
439
this . _error = error
440
- this . _setVersion ( INACTIVE )
440
+ this . _setEpoch ( INACTIVE )
441
441
return
442
442
}
443
443
this . _error = undefined
0 commit comments