Skip to content

Commit 855f326

Browse files
committed
refa: rename version to epoch
1 parent 2e4cc04 commit 855f326

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

packages/core/src/fiber.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface EffectMeta {
3434
}
3535

3636
interface EffectRunner<T> {
37-
version: T
37+
epoch: T
3838
execute: () => any
3939
collect: (dispose: Disposable) => void
4040
getOuterStack: () => string[]
@@ -109,7 +109,7 @@ export class Fiber<out C extends Context = Context> {
109109
}
110110

111111
this._runner = {
112-
version: INACTIVE,
112+
epoch: INACTIVE,
113113
getOuterStack,
114114
execute: () => {
115115
if (isConstructor(runtime.callback)) {
@@ -151,7 +151,7 @@ export class Fiber<out C extends Context = Context> {
151151
this.ctx.registry.delete(runtime.callback)
152152
}
153153
}
154-
this._setVersion(INACTIVE)
154+
this._setEpoch(INACTIVE)
155155
await this.await()
156156
}
157157
}, 'ctx.plugin()')
@@ -160,7 +160,7 @@ export class Fiber<out C extends Context = Context> {
160160
this.ctx = this.context = parent
161161
this.state = FiberState.ACTIVE
162162
this._runner = {
163-
version: '',
163+
epoch: '',
164164
getOuterStack,
165165
execute: () => {},
166166
collect,
@@ -184,7 +184,7 @@ export class Fiber<out C extends Context = Context> {
184184
}
185185

186186
private _execute<T>(runner: EffectRunner<T>) {
187-
const version = runner.version
187+
const oldEpoch = runner.epoch
188188
return composeError((info) => {
189189
const safeCollect = (dispose: void | Disposable) => {
190190
if (typeof dispose === 'function') {
@@ -217,7 +217,7 @@ export class Fiber<out C extends Context = Context> {
217217
await Promise.resolve()
218218
info.error = new Error()
219219
while (true) {
220-
if (runner.version !== version) return
220+
if (runner.epoch !== oldEpoch) return
221221
const result = await iter.next()
222222
safeCollect(result.value)
223223
if (result.done) return
@@ -253,7 +253,7 @@ export class Fiber<out C extends Context = Context> {
253253
const meta: EffectMeta = { label, children: [] }
254254
const runner: EffectRunner<boolean> = {
255255
execute,
256-
version: true,
256+
epoch: true,
257257
collect: (dispose) => {
258258
disposables.push(dispose)
259259
this._disposables.delete(dispose)
@@ -276,14 +276,14 @@ export class Fiber<out C extends Context = Context> {
276276
task?.catch(dispose)
277277

278278
const wrapper = defineProperty(() => {
279-
if (!runner.version) return
280-
runner.version = false
279+
if (!runner.epoch) return
280+
runner.epoch = false
281281
return task ? task.then(dispose) : dispose()
282282
}, symbols.effect, meta) as AsyncDisposable
283283

284284
const disposeAsync = () => {
285-
if (!runner.version) return
286-
runner.version = false
285+
if (!runner.epoch) return
286+
runner.epoch = false
287287
return dispose()
288288
}
289289
wrapper.then = async (onFulfilled, onRejected) => {
@@ -304,7 +304,7 @@ export class Fiber<out C extends Context = Context> {
304304
private _getState() {
305305
if (this.uid === null) return FiberState.DISPOSED
306306
if (this._error) return FiberState.FAILED
307-
if (this._runner.version !== INACTIVE) return FiberState.ACTIVE
307+
if (this._runner.epoch !== INACTIVE) return FiberState.ACTIVE
308308
return FiberState.PENDING
309309
}
310310

@@ -339,27 +339,27 @@ export class Fiber<out C extends Context = Context> {
339339
}
340340

341341
_refresh() {
342-
let version: string | boolean = false
343-
version = ''
342+
let epoch: string | boolean = false
343+
epoch = ''
344344
for (const [name, inject] of Object.entries(this.inject)) {
345345
if (!inject!.required) continue
346346
const impl = this._store[name]
347347
if (!impl) {
348-
version = INACTIVE
348+
epoch = INACTIVE
349349
break
350350
}
351-
version += ':' + impl.fiber.uid
351+
epoch += ':' + impl.fiber.uid
352352
}
353-
this._setVersion(version)
353+
this._setEpoch(epoch)
354354
}
355355

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
360360
if (this.inertia) return
361361
this._updateState(() => {
362-
if (version !== INACTIVE && oldVersion === INACTIVE) {
362+
if (epoch !== INACTIVE && oldEpoch === INACTIVE) {
363363
this.inertia = this._reload()
364364
return FiberState.LOADING
365365
} else {
@@ -371,18 +371,18 @@ export class Fiber<out C extends Context = Context> {
371371

372372
private async _reload() {
373373
this.store = { ...this._store }
374-
const version = this._runner.version
374+
const oldEpoch = this._runner.epoch
375375
try {
376376
await Promise.resolve()
377377
await this._execute(this._runner)
378378
} catch (reason) {
379379
// impl guarantees that the error is non-null (?)
380380
this.context.emit(this.ctx, 'internal/error', reason)
381381
this._error = reason
382-
this._runner.version = INACTIVE
382+
this._runner.epoch = INACTIVE
383383
}
384384
this._updateState(() => {
385-
if (this._runner.version === version) {
385+
if (this._runner.epoch === oldEpoch) {
386386
this.inertia = undefined
387387
} else {
388388
this.inertia = this._unload()
@@ -405,7 +405,7 @@ export class Fiber<out C extends Context = Context> {
405405
}))
406406
this.store = undefined
407407
this._updateState(() => {
408-
if (this._runner.version === INACTIVE) {
408+
if (this._runner.epoch === INACTIVE) {
409409
this.inertia = undefined
410410
} else {
411411
this.inertia = this._reload()
@@ -424,7 +424,7 @@ export class Fiber<out C extends Context = Context> {
424424

425425
async restart() {
426426
this.assertActive()
427-
this._setVersion(INACTIVE)
427+
this._setEpoch(INACTIVE)
428428
this._refresh()
429429
await this.await()
430430
}
@@ -437,7 +437,7 @@ export class Fiber<out C extends Context = Context> {
437437
} catch (error) {
438438
this.context.emit('internal/error', error)
439439
this._error = error
440-
this._setVersion(INACTIVE)
440+
this._setEpoch(INACTIVE)
441441
return
442442
}
443443
this._error = undefined

0 commit comments

Comments
 (0)