主要内容

wait

R2026b

Wait for futures running on MATLAB Production Server to complete

Since R2026b

    Description

    wait(F) suspends MATLAB® Production Server™ execution until each element of the prodserver.addon.FevalFuture array F is finished. When the function associated with a FevalFuture object finishes running, MATLAB Production Server sets the State property of the FevalFuture to 'Ready'.

    example

    wait(F,state) blocks MATLAB Production Server until each element of the Future array F has its State property set to state.

    tf = wait(F,state,timeout) blocks execution for a maximum of timeout seconds.

    If each element of the FevalFuture array F finishes before timeout seconds elapse, tf is true. Otherwise, tf is false.

    Examples

    collapse all

    Run a function in the background, then wait for the function to finish running.

    Use prodserver.addon.asyncfeval to run pause(5) without retrieving any outputs.

    Check the state of the FevalFuture.

    f.State
    ans = 'running'

    When you run asyncfeval, you schedule a function to run in the background. When the background pool has insufficient available resources to run the function, the FevalFuture is in the 'inQueue' state. When the function is run by the background pool, the FevalFuture is in the 'Processing' state.

    Wait for the function to finish running in the background. To block MATLAB Production Server until the function finishes running, use the wait function.

    wait(f)
    f.State
    ans = 'Ready'

    The function is now in the 'finished' state.

    Input Arguments

    collapse all

    Scheduled function to wait for the completion of, specified as an FevalFuture object.

    State to wait for, specified as "Ready" or "Processing".

    Seconds to wait for, specified as a real numeric scalar.

    Output Arguments

    collapse all

    If each element of the FevalFuture array F finishes before timeout seconds elapse, tf is true. Otherwise, tf is false.

    Version History

    Introduced in R2026b