Skip to content

Commit 1d4432b

Browse files
committed
io.launcher: Add run-processes and docs
1 parent c946ebf commit 1d4432b

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

basis/io/launcher/launcher-docs.factor

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,19 @@ HELP: run-process
127127
"T{ process\n { command \"pwd\" }\n { environment H{ } }\n { environment-mode +append-environment+ }\n { group +same-group+ }\n { status 0 }\n}"
128128
}
129129
}
130-
{ $notes "The output value can be passed to " { $link wait-for-process } " to get an exit code." } ;
130+
{ $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." } ;
131+
132+
HELP: run-processes
133+
{ $values { "descs" "a sequence of launch descriptors" } { "processes" "a sequence of " { $link process } } }
134+
{ $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." }
135+
{ $examples
136+
{ $unchecked-example
137+
"USING: io.launcher prettyprint ;"
138+
"{ \"ls\" \"ls\" } run-processes ."
139+
"{ 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} }"
140+
}
141+
}
142+
{ $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." } ;
131143

132144
HELP: run-detached
133145
{ $values { "desc" "a launch descriptor" } { "process" process } }
@@ -168,7 +180,7 @@ HELP: try-process
168180
}
169181
} ;
170182

171-
{ run-process try-process run-detached } related-words
183+
{ run-process run-processes try-process run-detached } related-words
172184

173185
HELP: kill-process
174186
{ $values { "process" process } }
@@ -281,9 +293,14 @@ ARTICLE: "io.launcher.launch" "Launching processes"
281293
"Launching processes:"
282294
{ $subsections
283295
run-process
296+
run-processes
284297
try-process
285298
run-detached
286299
}
300+
"Waiting for detached processes:"
301+
{ $subsections
302+
wait-for-process
303+
}
287304
"Redirecting standard input and output to a pipe:"
288305
{ $subsections
289306
<process-reader>

basis/io/launcher/launcher.factor

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ HOOK: (run-process) io-backend ( process -- handle )
164164
run-detached
165165
dup detached>> [ dup wait-for-process drop ] unless ;
166166

167+
: run-processes ( descs -- processes )
168+
[ run-process ] map ;
169+
167170
ERROR: process-failed process ;
168171

169172
M: process-failed error.
@@ -175,9 +178,14 @@ M: process-failed error.
175178
: check-success ( process status -- )
176179
0 = [ drop ] [ process-failed ] if ;
177180

178-
: wait-for-success ( process -- )
181+
GENERIC: wait-for-success ( obj -- )
182+
183+
M: process wait-for-success
179184
dup wait-for-process check-success ;
180185

186+
M: sequence wait-for-success
187+
[ wait-for-success ] each ;
188+
181189
: try-process ( desc -- )
182190
run-process wait-for-success ;
183191

0 commit comments

Comments
 (0)