@@ -161,7 +161,7 @@ The result is a real value representing the elapsed time in seconds, measured fr
161
161
162
162
### Syntax
163
163
164
- ` delta_t = ` [[ stdlib_subprocess(module): elapsed (interface )]] ` (process) `
164
+ ` delta_t = ` [[ stdlib_subprocess(module): elapsed (subroutine )]] ` (process) `
165
165
166
166
### Arguments
167
167
@@ -189,4 +189,46 @@ delta_t = elapsed(p)
189
189
print *, "Elapsed time (s): ", delta_t
190
190
```
191
191
192
+ ## ` wait ` - Wait until a running process is completed
192
193
194
+ ### Status
195
+
196
+ Experimental
197
+
198
+ ### Description
199
+
200
+ The ` wait ` interface provides a method to block the calling program until the specified process completes.
201
+ If the process is running asynchronously, this subroutine will pause the workflow until the given process finishes.
202
+ Additionally, an optional maximum wait time can be provided. If the process does not finish within the specified time,
203
+ the subroutine will return without waiting further.
204
+
205
+ On return from this routine, the process state is accordingly updated.
206
+ This is useful when you want to wait for a background task to complete, but want to avoid indefinite blocking
207
+ in case of process hang or delay.
208
+
209
+
210
+ ### Syntax
211
+
212
+ ` call ` [[ stdlib_subprocess(module): wait (subroutine)]] ` (process [, max_wait_time]) `
213
+
214
+ ### Arguments
215
+
216
+ ` process ` : Shall be a ` type(process_type) ` object representing the external process to monitor.
217
+ This is an ` intent(inout) ` argument, and its state is updated upon completion.
218
+
219
+ ` max_wait_time ` (optional): Shall be a ` real ` value specifying the maximum wait time in seconds.
220
+ If not provided, the subroutine will wait indefinitely until the process completes.
221
+
222
+ ### Example
223
+
224
+ ``` fortran
225
+ ! Example usage of wait
226
+ type(process_type) :: p
227
+
228
+ ! Start an asynchronous process
229
+ p = run("sleep 5", wait=.false.)
230
+
231
+ ! Wait for process to complete with a 10-second timeout
232
+ call wait(p, max_wait_time=10.0)
233
+ print *, "Process completed or timed out."
234
+ ```
0 commit comments