pub struct ExecutionSession<S: WorkflowState = State, M: MergeStrategy<S> = StateMerge>where
S::Checkpoint: Debug,{ /* private fields */ }Expand description
执行会话 — 持有 State 所有权 + FrameStack + Graph 引用。
§职责
- 持有 State 所有权(Engine 只是借用)
- 管理 FrameStack(Subgraph 执行时 push/pop)
- 创建和恢复 SessionCheckpoint
§设计原则
Graph 是 Immutable 的,多个 Session 共享同一个 Graph 实例。
Session 不拥有 Graph,只持有 Arc<Graph> 引用。
Runtime
└── Arc<Graph>
Session1 ──┐
Session2 ──┼── Arc<Graph>
Session3 ──┘Implementations§
Source§impl<S: WorkflowState, M: MergeStrategy<S>> ExecutionSession<S, M>where
S::Checkpoint: Debug,
impl<S: WorkflowState, M: MergeStrategy<S>> ExecutionSession<S, M>where
S::Checkpoint: Debug,
Sourcepub fn restore(
checkpoint: SessionCheckpoint<S>,
graph: Arc<Graph<S, M>>,
) -> Result<Self, SessionError>
pub fn restore( checkpoint: SessionCheckpoint<S>, graph: Arc<Graph<S, M>>, ) -> Result<Self, SessionError>
Sourcepub fn checkpoint(&self) -> SessionCheckpoint<S>
pub fn checkpoint(&self) -> SessionCheckpoint<S>
Sourcepub fn frame_stack(&self) -> &FrameStack<S>
pub fn frame_stack(&self) -> &FrameStack<S>
获取帧栈引用。
Sourcepub fn frame_stack_mut(&mut self) -> &mut FrameStack<S>
pub fn frame_stack_mut(&mut self) -> &mut FrameStack<S>
获取帧栈可变引用(用于 Subgraph 执行时 push/pop)。
Sourcepub fn into_state(self) -> S
pub fn into_state(self) -> S
消费会话,返回最终状态。
Sourcepub fn into_parts(self) -> (S, FrameStack<S>)
pub fn into_parts(self) -> (S, FrameStack<S>)
消费会话,返回 (状态, 帧栈)。
Source§impl<S: WorkflowState, M: MergeStrategy<S>> ExecutionSession<S, M>where
S::Checkpoint: Debug,
impl<S: WorkflowState, M: MergeStrategy<S>> ExecutionSession<S, M>where
S::Checkpoint: Debug,
Sourcepub async fn run_with(
&mut self,
engine: &mut ExecutionEngine<'_, S>,
) -> Result<(), GraphError>
pub async fn run_with( &mut self, engine: &mut ExecutionEngine<'_, S>, ) -> Result<(), GraphError>
使用指定的 Engine 执行。
Session 不知道 Stream,Engine 才知道 Stream。 职责分离:Session 负责 state + frame_stack,Engine 负责执行 + stream。
§示例
ⓘ
// 创建 Checkpoint Sink(可选)
let mut sink = SessionCheckpointSink::new(
session.frame_stack_mut(),
session.graph().name(),
);
let mut engine = ExecutionEngine::new(
session.state_mut(),
Some(stream), // Stream 由调用者提供
cancel,
Some(&mut sink), // 启用自动 checkpoint
None, // 不需要 Barrier Sink
);
session.run_with(&mut engine).await?;Trait Implementations§
Source§impl<S, M: MergeStrategy<S>> Default for ExecutionSession<S, M>
impl<S, M: MergeStrategy<S>> Default for ExecutionSession<S, M>
Auto Trait Implementations§
impl<S = State, M = StateMerge> !RefUnwindSafe for ExecutionSession<S, M>
impl<S = State, M = StateMerge> !UnwindSafe for ExecutionSession<S, M>
impl<S, M> Freeze for ExecutionSession<S, M>where
S: Freeze,
impl<S, M> Send for ExecutionSession<S, M>
impl<S, M> Sync for ExecutionSession<S, M>
impl<S, M> Unpin for ExecutionSession<S, M>
impl<S, M> UnsafeUnpin for ExecutionSession<S, M>where
S: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more