-
Notifications
You must be signed in to change notification settings - Fork 7
Control Flow
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.
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.
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 returning 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)
//Terminate the pipeline because required data couldn't be retrieved.
return null;
payload.Messages.Add($"Component {Name} called external api and returned result {payload.Result}");
return payload;
}
}