Function std.process.tryWait
A non-blocking version of wait
.
If the process associated with pid
has already terminated,
tryWait
has the exact same effect as wait
.
In this case, it returns a tuple where the terminated
field
is set to true
and the status
field has the same
interpretation as the return value of wait
.
If the process has not yet terminated, this function differs
from wait
in that does not wait for this to happen, but instead
returns immediately. The terminated
field of the returned
tuple will then be set to false
, while the status
field
will always be 0 (zero). wait
or tryWait
should then be
called again on the same Pid
at some later time; not only to
get the exit code, but also to avoid the process becoming a "zombie"
when it finally terminates. (See wait
for details).
Returns
An Tuple!(bool, "terminated", int, "status")
.
Throws
ProcessException
on failure or on attempt to wait for detached process.
Example
auto pid = spawnProcess("dmd myapp.d");
scope(exit) wait(pid);
...
auto dmd = tryWait(pid);
if (dmd .terminated)
{
if (dmd .status == 0) writeln("Compilation succeeded!");
else writeln("Compilation failed");
}
else writeln("Still compiling...");
...
Note that in this example, the first wait
call will have no
effect if the process has already terminated by the time tryWait
is called. In the opposite case, however, the scope
statement
ensures that we always wait for the process if it hasn't terminated
by the time we reach the end of the scope.
Authors
Lars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev