Main Content

wait

Wait for running blocks to complete

Since R2023a

Description

wait(pipeline) waits for the running blocks in the pipeline to complete or waits until the blocks are guaranteed not to complete for various reasons, including upstream errors or blocks not being selected to run, before executing the subsequent command.

example

wait(pipeline,blocks) waits for the specified blocks to complete or waits until the blocks are guaranteed not to complete.

Examples

collapse all

Import the Pipeline and block objects needed for the example.

import bioinfo.pipeline.Pipeline
import bioinfo.pipeline.block.*

Create a pipeline.

P = Pipeline;

Add some pause blocks for illustration purposes. Each block pauses with 10 seconds and 3 seconds, respectively.

PB1 = UserFunction(@() pause(10));
PB2 = UserFunction(@() pause(3));
addBlock(P,[PB1,PB2]);

Run the pipeline in parallel.

run(P,UseParallel=true);
Starting parallel pool (parpool) using the 'Processes' profile ...
Connected to parallel pool with 4 workers.

While the pipeline is still running and if you immediately execute the next commands to get the block results, you get a Running status instead.

results = processTable(P,Expanded=true)
results=2×5 table
         Block          Status           RunStart          RunEnd       RunErrors    
    ________________    _______    ____________________    ______    ________________

    "UserFunction_1"    Running    26-Jul-2023 09:27:48     NaT      {0×0 MException}
    "UserFunction_2"    Running    26-Jul-2023 09:27:48     NaT      {0×0 MException}

PB1Status = results(1,:);
PB1Status.Status
ans = 
  RunStatus enumeration

    Running

Instead use the wait function to wait for the running blocks to finish first and return the completed results afterwards.

wait(P);
results = processTable(P,Expanded=true)
results=2×5 table
         Block           Status            RunStart                 RunEnd              RunErrors    
    ________________    _________    ____________________    ____________________    ________________

    "UserFunction_1"    Completed    26-Jul-2023 09:27:48    26-Jul-2023 09:27:59    {0×0 MException}
    "UserFunction_2"    Completed    26-Jul-2023 09:27:48    26-Jul-2023 09:27:52    {0×0 MException}

PB1Status = results(1,:);
PB1Status.Status
ans = 
  RunStatus enumeration

    Completed

Input Arguments

collapse all

Bioinformatics pipeline, specified as a bioinfo.pipeline.Pipeline object.

Pipeline blocks, specified as a bioinfo.pipeline.Block object, vector of block objects, character vector, string scalar, string vector, or cell array of character vectors representing block names.

Version History

Introduced in R2023a