feat(godot): 添加协程扩展功能支持Mediator模式#30
Merged
Merged
Conversation
- 新增ContextAwareCoroutineExtensions类,提供IContextAware接口的协程扩展方法 - 实现RunCommandCoroutine、RunQueryCoroutine和RunPublishCoroutine方法 - 将原有CoroutineExtensions重命名为CoroutineNodeExtensions并迁移相关功能 - 添加文件头版权信息到新的协程扩展类 - 重构协程生命周期管理方法,包括RunCoroutine和CancelWith系列方法 - 移除测试文件中关于日志行为的占位测试用例
Reviewer's GuideAdds context-aware coroutine extensions to integrate Mediator-style commands/queries/notifications with Godot coroutines, refactors existing coroutine node extensions for clearer lifecycle management, and removes an obsolete logging-related test placeholder. Sequence diagram for RunCommandCoroutine integration with Mediator and Godot coroutine timingsequenceDiagram
actor GodotNode
participant ContextAware as IContextAware
participant Mediator as MediatorPipeline
participant TaskApi as TaskExtensions
participant CoroutineNodeExtensions
participant Timing
GodotNode->>ContextAware: RunCommandCoroutine(command, segment, tag, cancellationToken)
activate ContextAware
ContextAware->>Mediator: SendCommandAsync(command, cancellationToken)
activate Mediator
Mediator-->>ContextAware: ValueTask
deactivate Mediator
ContextAware->>TaskApi: AsTask() on ValueTask
activate TaskApi
TaskApi-->>ContextAware: Task
deactivate TaskApi
ContextAware->>TaskApi: ToCoroutineEnumerator(Task)
activate TaskApi
TaskApi-->>ContextAware: IEnumerator IYieldInstruction
deactivate TaskApi
ContextAware->>CoroutineNodeExtensions: RunCoroutine(coroutineEnumerator, segment, tag)
activate CoroutineNodeExtensions
CoroutineNodeExtensions->>Timing: RunCoroutine(coroutineEnumerator, segment, tag)
activate Timing
Timing-->>CoroutineNodeExtensions: CoroutineHandle
deactivate Timing
CoroutineNodeExtensions-->>GodotNode: CoroutineHandle
deactivate CoroutineNodeExtensions
deactivate ContextAware
Sequence diagram for node-lifecycle-aware CancelWith coroutine wrappersequenceDiagram
participant GameNode as Node
participant Caller as CallerScript
participant CoroutineNodeExtensions
participant Timing
Caller->>CoroutineNodeExtensions: CancelWith(coroutine, node)
activate CoroutineNodeExtensions
loop while Timing.IsNodeAlive(node) and coroutine.MoveNext()
CoroutineNodeExtensions->>Timing: IsNodeAlive(node)
Timing-->>CoroutineNodeExtensions: bool
alt node alive
CoroutineNodeExtensions->>CoroutineNodeExtensions: coroutine.MoveNext()
CoroutineNodeExtensions-->>Caller: yield coroutine.Current
else node destroyed
note right of CoroutineNodeExtensions: break
end
end
deactivate CoroutineNodeExtensions
Class diagram for new context-aware and node coroutine extensionsclassDiagram
direction LR
class ContextAwareCoroutineExtensions {
<<static>>
+CoroutineHandle RunCommandCoroutine(IContextAware contextAware, ICommand command, Segment segment, string tag, CancellationToken cancellationToken)
+CoroutineHandle RunCommandCoroutine~TResponse~(IContextAware contextAware, ICommand~TResponse~ command, Segment segment, string tag, CancellationToken cancellationToken)
+CoroutineHandle RunQueryCoroutine~TResponse~(IContextAware contextAware, IQuery~TResponse~ query, Segment segment, string tag, CancellationToken cancellationToken)
+CoroutineHandle RunPublishCoroutine(IContextAware contextAware, INotification notification, Segment segment, string tag, CancellationToken cancellationToken)
}
class CoroutineNodeExtensions {
<<static>>
+CoroutineHandle RunCoroutine(IEnumerator~IYieldInstruction~ coroutine, Segment segment, string tag)
+IEnumerator~IYieldInstruction~ CancelWith(IEnumerator~IYieldInstruction~ coroutine, Node node)
+IEnumerator~IYieldInstruction~ CancelWith(IEnumerator~IYieldInstruction~ coroutine, Node node1, Node node2)
+IEnumerator~IYieldInstruction~ CancelWith(IEnumerator~IYieldInstruction~ coroutine, Node[] nodes)
-bool AllNodesAlive(Node[] nodes)
}
class Timing {
+static CoroutineHandle RunCoroutine(IEnumerator~IYieldInstruction~ coroutine, Segment segment, string tag)
+static bool IsNodeAlive(Node node)
}
class IContextAware {
<<interface>>
+ValueTask SendCommandAsync(ICommand command, CancellationToken cancellationToken)
+ValueTask~TResponse~ SendCommandAsync~TResponse~(ICommand~TResponse~ command, CancellationToken cancellationToken)
+ValueTask~TResponse~ SendQueryAsync~TResponse~(IQuery~TResponse~ query, CancellationToken cancellationToken)
+ValueTask PublishEventAsync(INotification notification, CancellationToken cancellationToken)
}
class ICommand {
<<interface>>
}
class ICommandTResponse {
<<interface>>
ICommand~TResponse~
}
class IQueryTResponse {
<<interface>>
IQuery~TResponse~
}
class INotification {
<<interface>>
}
class CoroutineHandle
class IYieldInstruction
class Node
class Segment
class CancellationToken
class IEnumeratorIYieldInstruction {
IEnumerator~IYieldInstruction~
}
ContextAwareCoroutineExtensions ..> IContextAware : extends
ContextAwareCoroutineExtensions ..> ICommand
ContextAwareCoroutineExtensions ..> ICommandTResponse
ContextAwareCoroutineExtensions ..> IQueryTResponse
ContextAwareCoroutineExtensions ..> INotification
ContextAwareCoroutineExtensions ..> CoroutineHandle
ContextAwareCoroutineExtensions ..> Segment
ContextAwareCoroutineExtensions ..> CancellationToken
ContextAwareCoroutineExtensions ..> CoroutineNodeExtensions : uses RunCoroutine
CoroutineNodeExtensions ..> IEnumeratorIYieldInstruction
CoroutineNodeExtensions ..> IYieldInstruction
CoroutineNodeExtensions ..> CoroutineHandle
CoroutineNodeExtensions ..> Segment
CoroutineNodeExtensions ..> Node
CoroutineNodeExtensions ..> Timing : uses
Timing ..> CoroutineHandle
Timing ..> IYieldInstruction
Timing ..> Node
IContextAware ..> ICommand
IContextAware ..> ICommandTResponse
IContextAware ..> IQueryTResponse
IContextAware ..> INotification
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Add context-aware coroutine extensions for Mediator integration and refine Godot coroutine lifecycle utilities.
New Features:
Enhancements:
Tests: