This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace ShrinkContext
|
||||
{
|
||||
public enum ShrinkFiberState
|
||||
{
|
||||
Inactive = 0,
|
||||
Loading = 1,
|
||||
Active = 2,
|
||||
Unloading = 3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 纤程(论文定义 44):组件的一次运行时实例化。
|
||||
/// 生命周期由 Target(期望提供者集合,null 即 ⊥)与惯性状态机驱动:
|
||||
/// 一旦进入转换即运行至完成,之后才响应新的目标变化(算法 5)。
|
||||
/// </summary>
|
||||
public sealed class ShrinkFiber
|
||||
{
|
||||
internal ShrinkFiber(long uid, IShrinkComponent component, ShrinkFiber? parent, object? config)
|
||||
{
|
||||
Uid = uid;
|
||||
Component = component;
|
||||
Parent = parent;
|
||||
Config = config;
|
||||
InjectSet = new HashSet<string>(component.Inject ?? Array.Empty<string>(), StringComparer.Ordinal);
|
||||
ProvideSet = new HashSet<string>(component.Provide ?? Array.Empty<string>(), StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
public long Uid { get; }
|
||||
|
||||
public string Name => Component.Name;
|
||||
|
||||
public IShrinkComponent Component { get; }
|
||||
|
||||
/// <summary>实例化该纤程时的父纤程(根级为 null);父纤程卸载会级联到本纤程。</summary>
|
||||
public ShrinkFiber? Parent { get; }
|
||||
|
||||
/// <summary>本纤程运行所在的派生子上下文。</summary>
|
||||
public ShrinkCtx Ctx { get; internal set; } = null!;
|
||||
|
||||
public object? Config { get; }
|
||||
|
||||
public ShrinkFiberState State { get; internal set; } = ShrinkFiberState.Inactive;
|
||||
|
||||
/// <summary>是否到达过 Active(用于断言“从未激活”)。</summary>
|
||||
public bool EverActive { get; internal set; }
|
||||
|
||||
/// <summary>最近一次 apply 抛出的异常;成功激活后清空。</summary>
|
||||
public Exception? LastError { get; internal set; }
|
||||
|
||||
/// <summary>已提交视图(算法 5 reload 提交 / 算法 6 读取):依赖键 → 绑定快照。</summary>
|
||||
public IReadOnlyDictionary<string, ShrinkBinding>? Committed => _committed;
|
||||
|
||||
/// <summary>进行中转换的句柄;任务在纤程到达静止态(Active 或 Inactive)时完成。</summary>
|
||||
public UniTask Inertia { get; internal set; }
|
||||
|
||||
internal Dictionary<string, ShrinkBinding>? _committed;
|
||||
internal long[]? Target;
|
||||
internal bool InTransition;
|
||||
internal bool Retired;
|
||||
internal HashSet<string> InjectSet { get; }
|
||||
internal HashSet<string> ProvideSet { get; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user