FlowState: add Status, thread invoker Task, simplify resume/interrupt#154
Open
stidsborg wants to merge 1 commit into
Open
FlowState: add Status, thread invoker Task, simplify resume/interrupt#154stidsborg wants to merge 1 commit into
stidsborg wants to merge 1 commit into
Conversation
- FlowState constructor takes a completion Task and hooks ContinueWith to flip Status to Completed once the invoker's TaskCompletionSource resolves. Setter guards Completed as terminal. - Implement Waiting() as Subflows == WaitingSubflows. - Replace TryResumeSubflow() (bool) with ResumeSubflow() returning ForeverTask.Instance when suspended or Task.CompletedTask otherwise; collapses the QueueManager call site to a single await. - Drop WaitingSubflows = 0 in Interrupt(): it desynchronised the counter (later ResumeSubflow calls drove it negative, blocking future Suspend()). - Invoker creates the TCS before PrepareFor[Re]Invocation and threads tcs.Task through CreateFlowState so FlowState can observe completion. Scaffolding for centralized suspension via FlowsManager; nothing calls Suspend() yet, so behaviour is unchanged.
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
Scaffolding for centralised suspension via
FlowsManager. No behaviour change yet — nothing callsFlowState.Suspend()in this PR.FlowStateconstructor now takes a completionTaskand hooks aContinueWiththat flipsStatustoCompletedwhen the invoker'sTaskCompletionSourceresolves. Setter guardsCompletedas terminal.Waiting()returnsSubflows == WaitingSubflows.TryResumeSubflow()(returning bool) becomesResumeSubflow()returningForeverTask.Instancewhen suspended orTask.CompletedTaskotherwise. Call site inQueueManager.Subscribecollapses to a singleawait.Interrupt()no longer zerosWaitingSubflows: that desynchronised the counter — subsequentResumeSubflowcalls drove it negative, which silently prevented futureSuspend()from ever triggering. Now it just delegates toQueueManager.Interrupt()when not suspended.Invokercreates itsTaskCompletionSourcebeforePrepareFor[Re]Invocationand threadstcs.TaskthroughCreateFlowState, soFlowStatecan observe the invocation's terminal state directly.Test files that hand-roll
FlowState/CreateFlowState(PrintEffectsTests,EffectTests,MessagesSubscriptionTests) now passForeverTask.Instancefor the completion Task.Follow-ups (not in this PR)
CheckForSuspensionloop inFlowsManagerand start it fromFunctionsRegistry.Suspend()fault liveQueueManagersubscriptions withSuspendInvocationExceptionso the user-function task exits and the existingPersistResultpath runs.MessagesDefaultMaxWaitForCompletionfrom per-subscription auto-suspension inQueueManager.Subscribe.Test plan
PingPongMessagesCanBeExchangedMultipleTimesis pre-existing (reproduced onmainbaseline without this branch)