Running pipeline blocks synchronously or asynchronously
Starting with Sitecore XC 10.0, all pipeline blocks derive from either the AsyncPipelineBlock class or the SyncPipelineBlock class, depending on whether a method must run asynchronously or synchronously.
Using the AsyncPipelineBlock and SyncPipelineBlock classes
To execute a pipeline block synchronously, use the SyncPipelineBlock class. The method name used to run a block synchronously is Run(). For example:
To run a pipeline block asynchronously, use the AsyncPipelineBlock. The method name used to run a block asynchronously is RunAsync(). For example:
The IPipeline RunAsync() method
Starting with Sitecore XC 10.0, the IPipeline interface method is changed from Run to RunAsync() because the method is an asynchronous operation.
Each pipeline can use a combination of synchronous and asynchronous blocks.
Conditional pipeline blocks
Starting with Sitecore 10.0, all conditional pipeline blocks must derive from either one of the following synchronous or asynchronous block classes:
-
ConditionalPipelineBLock -
AsyncConditionalPipelineBLock
To run a conditional pipeline block synchronously, you derive it from the ConditionalPipelineBLock class. For example:
To run a conditional block asynchronously, you derive it from the AsyncConditionalPipelineBLock class. For example:
Policy trigger conditional blocks
Starting with Sitecore 10.0, all policy trigger conditional blocks must derive from one of the following synchronous or asynchronous pipeline block classes:
-
SyncPolicyTriggerConditionalPipelineBLock -
AsyncPolicyTriggerConditionalPipelineBLock
A policy trigger block sets a header in the context that stops the block from running. For example, to skip cart calculation in a block, set ShouldNotRunPolicyTrigger to "DoNotCalculateCart".
To run a policy trigger conditional block synchronously, you derive it from the SyncPolicyTriggerConditionalPipelineBLock class. For example:
To run a policy trigger conditional block asynchronously, you derive it from the AsyncPolicyTriggerConditionalPipelineBLock class. For example: