Last active
July 29, 2025 14:13
-
-
Save cablehead/def5993df09717291e4f33c7dc7b789d to your computer and use it in GitHub Desktop.
Revisions
-
cablehead revised this gist
Jul 29, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # Spawn xs serve in a temporary directory, run a closure, then cleanup def .tmp-spawn [closure: closure] { # Create a temporary directory let tmp_dir = (mktemp -d) print $"Created temp directory: ($tmp_dir)" -
cablehead created this gist
Jul 29, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ # Spawn xs serve in a temporary directory, run a closure, then cleanup export def main [closure: closure] { # Create a temporary directory let tmp_dir = (mktemp -d) print $"Created temp directory: ($tmp_dir)" let store_path = ($tmp_dir | path join "store") try { # Create store directory mkdir $store_path # Spawn xs serve in the background let job_id = job spawn --tag "xs-test-server" { xs serve $store_path } print $"Started xs serve with job ID: ($job_id)" $env.XS_ADDR = $store_path $env.XS_CONTEXT = null # Give the server a moment to start up sleep 50ms try { # Run the provided closure do $closure | print $in } catch { |err| error make {msg: $"Error in closure: ($err.msg)"} } # Kill the background job job kill $job_id print $"Killed xs serve job ($job_id)" # Give a moment for the job to shut down sleep 50ms } catch { |err| print $"Error during setup: ($err.msg)" } # Clean up the temporary directory try { rm -rf $tmp_dir print $"Cleaned up temp directory: ($tmp_dir)" } catch { |err| print $"Warning: Could not clean up temp directory: ($err.msg)" } }