]> gitweb.factorcode.org Git - factor.git/commitdiff
io.launcher: Add run-processes and docs
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 25 Mar 2023 00:35:25 +0000 (19:35 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 25 Mar 2023 00:35:25 +0000 (19:35 -0500)
basis/io/launcher/launcher-docs.factor
basis/io/launcher/launcher.factor

index 2a3d8b319075c9070947e4b54519b9162c096d73..8c0624a67d01de690e9a9f32f16d51236bbd7780 100644 (file)
@@ -127,7 +127,19 @@ HELP: run-process
     "T{ process\n    { command \"pwd\" }\n    { environment H{ } }\n    { environment-mode +append-environment+ }\n    { group +same-group+ }\n    { status 0 }\n}"
   }
 }
-{ $notes "The output value can be passed to " { $link wait-for-process } " to get an exit code." } ;
+{ $notes "The output value will either have the exit code set or can be passed to " { $link wait-for-process } " to get an exit code in the case of a " { $snippet "detached" } " process." } ;
+
+HELP: run-processes
+{ $values { "descs" "a sequence of launch descriptors" } { "processes" "a sequence of " { $link process } } }
+{ $description "Launches a sequence of processes that will execute in serial by default or in parallel if " { $snippet "detached" } " is true. Each desc can either be a string, a sequence of strings or a " { $link process } ". See " { $link "io.launcher.descriptors" } " for details." }
+{ $examples
+  { $unchecked-example
+    "USING: io.launcher prettyprint ;"
+    "{ \"ls\" \"ls\" } run-processes ."
+    "{ T{ process\n    { command \"ls\" }\n    { environment H{ } }\n    { environment-mode +append-environment+ }\n    { group +same-group+ }\n    { status 0 }\n}\nT{ process\n    { command \"ls\" }\n    { environment H{ } }\n    { environment-mode +append-environment+ }\n    { group +same-group+ }\n    { status 0 }\n} }"
+  }
+}
+{ $notes "The output values will have an exit code set or can be passed to " { $link wait-for-process } " to get an exit code in the case of " { $snippet "detached" } " processes." } ;
 
 HELP: run-detached
 { $values { "desc" "a launch descriptor" } { "process" process } }
@@ -168,7 +180,7 @@ HELP: try-process
   }
 } ;
 
-{ run-process try-process run-detached } related-words
+{ run-process run-processes try-process run-detached } related-words
 
 HELP: kill-process
 { $values { "process" process } }
@@ -281,9 +293,14 @@ ARTICLE: "io.launcher.launch" "Launching processes"
 "Launching processes:"
 { $subsections
     run-process
+    run-processes
     try-process
     run-detached
 }
+"Waiting for detached processes:"
+{ $subsections
+    wait-for-process
+}
 "Redirecting standard input and output to a pipe:"
 { $subsections
     <process-reader>
index f2b0d0b8d88dd1c04922d73d2af8d9cc4c95b049..2250a39dd88ff33a929ac67cc741d547878e43c9 100644 (file)
@@ -164,6 +164,9 @@ HOOK: (run-process) io-backend ( process -- handle )
     run-detached
     dup detached>> [ dup wait-for-process drop ] unless ;
 
+: run-processes ( descs -- processes )
+    [ run-process ] map ;
+
 ERROR: process-failed process ;
 
 M: process-failed error.
@@ -175,9 +178,14 @@ M: process-failed error.
 : check-success ( process status -- )
     0 = [ drop ] [ process-failed ] if ;
 
-: wait-for-success ( process -- )
+GENERIC: wait-for-success ( obj -- )
+
+M: process wait-for-success
     dup wait-for-process check-success ;
 
+M: sequence wait-for-success
+    [ wait-for-success ] each ;
+
 : try-process ( desc -- )
     run-process wait-for-success ;