Sometimes it is useful to be able to control the flow of execution while a protocol is executing. For that purpose, PilotScript provides a set of control functions. The Error() function is perhaps the most well-known. It allows for a custom error to be thrown and the protocol execution to be stopped. However, there is another function that provides a more nuanced control over execution, and that is TerminatePipeline(). This function can end the execution of the current pipeline that contains the component running the script but allow the rest of the protocol to finish execution. Three different options are available:
- DownStream: the script component and all downstream components are terminated immediately. No finalization occurs but upstream components continue to run.
- UpAndDownStream: as above, but also shuts down upstream components on all pipelines connected to this component.
- Source: all upstream components are terminated, shutting off the source of data for the pipelines flowing through the component, with the additional option of directing the current record to the pass, fail or no port.
Using TerminatePipeline('Source') provides a similar behaviour as the Create Empty Data component discussed in an earlier post, but for an existing data source. It can be used to stop reading from a data source once a condition has been met.
This PilotScript function can make your protocol more efficient by avoiding execution of time-consuming parts of the protocol that don't need to be executed, so give it a try.