wait
Method of timer objects: blocks until the timer has finished running.
Category: Programming > Programming Utilities
Syntax
wait(t)
Pauses the script until the timer t is no longer running.
Description
A started timer runs in the background, so a script that ends right after start may finish before the callback ever runs. wait makes the script block until all the timer's tasks are done, or until it is stopped. A repeating timer with TasksToExecute left at Inf never finishes by itself, so wait would block until stop is called elsewhere.
Input arguments
t- A timer object.
Example
Waiting for two repetitions
t = timer('ExecutionMode', 'fixedRate', 'Period', 0.01, ...
'TasksToExecute', 2, 'TimerFcn', @(~,~) disp('tick'));
start(t)
wait(t)
disp('finished')
delete(t)
Output
tick
tick
finished