RunMat
GitHub

pause — Suspend execution until the user presses a key or a specified time elapses.

pause suspends execution and mirrors MATLAB's timing semantics:

  • pause with no inputs waits for keyboard input (press any key) while pause mode is on.
  • pause(t) delays execution for t seconds (non-negative numeric scalar). t = Inf behaves like pause with no arguments.
  • pause('on') and pause('off') enable or disable pausing globally, returning the previous state ('on' or 'off').
  • pause('query') reports the current state ('on' or 'off').
  • pause([]) is treated as pause with no arguments.
  • When pause mode is off, delays and key waits complete immediately.

Invalid usages (negative times, non-scalar numeric inputs, or unknown strings) raise RunMat:pause:InvalidInputArgument, matching MATLAB diagnostics.

How pause runs on the GPU

pause never runs on the GPU. When you pass GPU-resident values (for example, pause(gpuArray(0.5))), RunMat automatically gathers them to the host before evaluating the delay. No residency changes occur otherwise, and acceleration providers do not receive any callbacks.

GPU memory and residency

pause never runs on the GPU. When you pass GPU-resident values (for example, pause(gpuArray(0.5))), RunMat automatically gathers them to the host before evaluating the delay. No residency changes occur otherwise, and acceleration providers do not receive any callbacks.

Examples

Pausing for a fixed duration

tic;
pause(0.05);     % wait 50 milliseconds
elapsed = toc

Waiting for user input mid-script

disp("Press any key to continue the demo...");
pause;           % waits until the user presses a key (while pause is 'on')

Temporarily disabling pauses in automated runs

state = pause('off');   % returns previous state so it can be restored
cleanup = onCleanup(@() pause(state));  % ensure state is restored
pause(1.0);             % returns immediately because pause is disabled

Querying the current pause mode

current = pause('query');   % returns 'on' or 'off'

Using empty input to rely on the default behaviour

pause([]);   % equivalent to calling pause with no arguments

FAQ

Does pause block forever when standard input is not interactive?

No. When RunMat detects a non-interactive standard input (for example, during automated tests), pause completes immediately even in 'on' mode.

What happens if I call pause with a negative duration?

RunMat raises RunMat:pause:InvalidInputArgument, matching MATLAB.

Does pause accept logical or integer values?

Yes. Logical and integer inputs are converted to doubles before evaluating the delay.

Can I force pausing off globally?

Use pause('off') to disable pauses. Record the return value so you can restore the prior state with pause(previousState).

Does pause('query') change the pause state?

No. It simply reports the current mode ('on' or 'off').

Is pause affected by GPU fusion or auto-offload?

No. The builtin runs on the host regardless of fusion plans or acceleration providers.

What is the default pause state?

'on'. Every RunMat session starts with pausing enabled.

Can I pass a gpuArray as the duration?

Yes. RunMat gathers the scalar duration to the host before evaluating the delay.

These functions work well alongside pause. Each page has runnable examples you can try in the browser.

tic, toc, timeit

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how pause works, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat — free, no sign-up

Start running MATLAB code immediately in your browser.