Files
ShrinkContext.Core/Runtime/Fibers/IShrinkComponent.cs
T
cneicy 6eebb8e8e4
Publish UPM package / publish (push) Failing after 1s
chore: initialize standalone UPM package
2026-08-26 02:49:58 +08:00

48 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#nullable enable
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
namespace ShrinkContext
{
/// <summary>
/// 组件 = (inject 依赖键集合 d, provide 供给键集合 p, apply 效应函数 e)(论文定义 43)。
/// apply 内部通过 ctx.Set 提供依赖、ctx.Get 消费依赖、ctx.Effect 注册可逆效应;
/// 组件的拆卸由运行时按已追踪的逆操作自动推导,无需手写卸载路径。
/// </summary>
public interface IShrinkComponent
{
string Name { get; }
/// <summary>声明的依赖键集合(论文 d):全部可用时组件才激活。</summary>
IReadOnlyList<string> Inject { get; }
/// <summary>供给键集合(论文 p):apply 的效应不应写入 p 之外的键。</summary>
IReadOnlyList<string> Provide { get; }
/// <summary>效应函数(论文 e):激活时执行;其中注册的效应在停用时按 LIFO 回滚。</summary>
UniTask ApplyAsync(ShrinkCtx ctx, object? config);
}
/// <summary>
/// 分步效应组件(论文 𝔈iterΓ):apply 以步进器逐步产出逆操作。
/// 目标在步进边界发生变化时中断迭代并回滚已执行步骤(部分回滚,论文 4.3.2 / 定理 64)。
/// 使用自定义 UniTask 步进协议而非 IAsyncEnumerable
/// Mono 的 ValueTask 迭代器恢复经同步上下文调度,会破坏同步内联的确定性语义。
/// </summary>
public interface IShrinkIterativeComponent : IShrinkComponent
{
IShrinkStepEffectEnumerator ApplySteps(ShrinkCtx ctx, object? config);
}
/// <summary>分步效应步进器:MoveNextAsync 执行该步前向并使 Current 指向其逆操作。</summary>
public interface IShrinkStepEffectEnumerator
{
/// <summary>推进到下一步;返回 false 表示迭代结束。前向在该调用内执行完毕。</summary>
UniTask<bool> MoveNextAsync();
/// <summary>最近一次 MoveNextAsync 成功后该步的逆操作。</summary>
Func<UniTask> Current { get; }
}
}