知识卡片
状态机显式处理事件
状态机把允许的变化写作由现有状态和输入事件决定的规则。枚举可携带每个状态专属数据。帮助检查重复事件、无效事件和异常分支。调度及副作用应明确由何处提交,以免失败后状态与动作分离。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 9. Design Patterns 枚举和事件说明状态迁移 · 查看原书依据
State machines hold a particular state as well as logic around how that state is changed. Other processes can reference that state to inform the way they act; this is the state machine pattern. A simple real-world example of a state machine is a set of traffic lights. Depending on the country, traffic lights can vary, but they all have at least two states: red
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第09章《Chapter 9. Design Patterns》,枚举和事件说明状态迁移(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch09.html#id60)
- 结论依据:交通灯和开关示例把状态、事件与转移逻辑独立表达。
- 原始内容:State machines hold a particular state as well as logic around how that state is changed. Other processes can reference that state to inform the way they act; this is the state machine pattern. A simple real-world example of a state machine is a set of traffic lights. Depending on the country, traffic lights can vary, but they all have at least two states: red