Repository navigation
Start background processes, clean up and run steps at once in shell { } - #47
Merged
Merged
Conversation
…esses
A caller of `Proc.StartLongRunning` could stop the process but not see whether it had exited on its own, or wait
for it. `Proc.Fs` needs both to check background processes in `shell { }`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A `shell { }` block ran one command after another, so it could not start a server, run commands against it and
stop it, and nested blocks did not share the directory or environment. `background` starts a process and stops it
at the end of the scope, failing the next command when it crashes. `defer` runs clean-up at the end of a scope.
`steps { }` is a block that runs where it is used, and `concurrently` runs such blocks at the same time, stopping
the others when one fails. A failing clean-up no longer hides the error of the scope it cleans up after.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A
shell { }block can now start a background process and stop it at the end of a scope, run clean-up commands at the end of a scope, and run blocks at the same time.Prompt summary: The author asks whether
shell { }blocks can be composed with concurrency control: one block starts a background process, another runs commands against it, and the first is torn down at the end. This PR answers that with new steps inshell { }, plus the small C# API they need.Why
A
shell { }block runs one command after another on one thread.use _ = exec { wait_until … }starts a server, but it ignores the block'scdandenv, and a crash of the server goes unnoticed. A nestedshell { }runs as soon as it is evaluated and starts with a fresh directory and environment, so blocks can not be passed around or run at the same time.What
Background processes
background cmdstarts a process in the block's directory and environment. WithCmd.waitFor, it first waits for a line that says the process is ready. On a background command,Cmd.timeoutlimits only that wait, as withwait_untilinexec { }. When the process exits with an exit code it does not accept, the next command of the block throws, likeset -e.use!stops it at the end of the scope (Ctrl+C, a kill after 10 seconds), and the block stops whatever is still running when it ends.wait pwaits for the process and checks its exit code.Clean-up at the end of a scope
defer cmdruns a command at the end of the scope, also when the scope fails, liketrap … EXIT. When the scope fails and its clean-up fails too, the scope's exception now propagates and the clean-up failure goes to standard error. Before, the clean-up failure replaced the original error.Blocks that run later, and at the same time
steps { }is ashell { }block that runs where it is used, in the directory and environment of the block that uses it.concurrentlyandconcurrentlyAtMost nrun such blocks at the same time and return their results in order. Each branch gets its own copy of the directory and environment. The first branch that fails stops the others through a cancellation token, which now flows through every command the runner starts.parallelis reserved in F#, hence the name.Long-running processes report how they ended
LongRunningApplicationSubscriptiongainsProcessId,ExitCodeandWaitForCompletion, whichbackgroundbuilds on. The READMEs now documentProc.StartLongRunningand the new steps.Verify
Out of scope: output of concurrent branches interleaves line by line; a prefix per branch would be a follow-up. Windows was not tried locally.
🤖 Generated with Claude Code