Skip to content

Control Flow

Marty Mathis edited this page Jan 20, 2019 · 9 revisions

When a pipeline is executed, all components the pipeline is comprised of will be executed in the order specified. This will always occur unless one of two things happens.

Unhandled Exception

If an unhandled exception occurs in an underlying component during pipeline execution, this will terminate the pipeline without it finishing execution of any remaining components.

Component Specified Termination

There are certain scenarios where you might want a component to signal the pipeline is done executing for one reason or another. For example, a required api call might have failed to retrieve data required for the next component scheduled to execute. In this case, the component understands the pipeline really can't continue without the required data so it signals the framework to terminate execution. This is done by return null from the component like so:

    public class BarComponent : AsyncPipelineComponentBase<ExamplePipelinePayload>
    {
        public override async Task<ExamplePipelinePayload> ExecuteAsync(ExamplePipelinePayload payload, CancellationToken cancellationToken)
        {
            payload.Result = await Task.Run(() =>
                {
                    //call some external api and get null result back
                    return null as object;
                },
                cancellationToken);
            
            if (payload.Result == null)
                return null;  //Terminate the pipeline because required data couldn't be retrieved.

            payload.Messages.Add($"Component {Name} called external api and returned result {payload.Result}");

            return payload;
        }
    }
Clone this wiki locally