Cancel queued or running future
cancel(F) stops the queued
and running futures contained in
F. No action is
taken for finished futures. Each element of
is not already in state
'finished' has its
'finished', and its
is set to contain an MException indicating that execution was cancelled.
Run a function several times until a satisfactory result is
found. In this case, the array of futures
cancelled when a result is greater than 0.95.
N = 100; for idx = N:-1:1 F(idx) = parfeval(@rand,1); % Create a random scalar end result = NaN; % No result yet. for idx = 1:N [~, thisResult] = fetchNext(F); if thisResult > 0.95 result = thisResult; % Have all the results needed, so break break; end end % With required result, cancel any remaining futures cancel(F) result