wait - Wait for futures to complete - MATLAB (original) (raw)
Main Content
Wait for futures to complete
Syntax
Description
wait([F](#mw%5F30b63939-568f-4782-9b0a-588265fbb8bc))
suspends MATLABĀ® execution until each element of the Future
arrayF
is finished. When the function associated with aFuture
object finishes running, MATLAB sets the State
property of the Future
to'finished'
.
wait([F](#mw%5F30b63939-568f-4782-9b0a-588265fbb8bc),[state](#mw%5F6ff5150c-5074-4ffe-8aac-66ba6c702ad3))
blocks MATLAB until each element of the Future
array F
has its State
property set to state
.
`tf` = wait([F](#mw%5F30b63939-568f-4782-9b0a-588265fbb8bc),[state](#mw%5F6ff5150c-5074-4ffe-8aac-66ba6c702ad3),[timeout](#mw%5F0bd9fa41-16d9-445f-82fb-57e62afa42ca))
blocks execution for a maximum of timeout
seconds.
If each element of the Future
array F
finishes before timeout
seconds elapse, tf
istrue
. Otherwise, tf
isfalse
.
Examples
Run a function in the background, then wait for the function to finish running.
Use parfeval
to run pause(5)
without retrieving any outputs. Specify backgroundPool
as the first argument to run the function in the background. When you use parfeval
, you create a Future
object.
f = parfeval(backgroundPool,@pause,0,5);
Check the state of the Future
.
When you run parfeval
, you schedule a function to run in the background. When the background pool has insufficient available resources to run the function, the Future
is in the 'queued'
state. When the function is run by the background pool, the Future
is in the'running'
state.
Wait for the function to finish running in the background. When you wait for the function to finish running, you block MATLAB until the function finishes running.
The function is now in the 'finished'
state.
Input Arguments
Input Future
, specified as a parallel.Future
scalar or array.
State to wait for, specified as "finished"
or"running"
.
Seconds to wait for, specified as a real numeric scalar.
Example: timeout = 5;
Example: timeout = single(3.14);
Version History
Introduced in R2013b