ReturnFailure
The return failure task will always return failure except when the child task is running.
子Task运行期间将一直返回失败。主要重载了Decorate函数。在父类中的意义是申请改变子Task的状态。从代码上看也是这样,子Task的状态是成功,那么久返回失败;如果是失败,那还是返回失败。需要注意的是,如果是子Task是Running那还是返回Running。也就是说对Running的子Task不起作用,比如内置的Idle 或者 Wait。
Decorator的设计目的就是改变子Task的状态,ReturnFailure是通过修改自身的状态来达到这一目的,而上一篇介绍的UntilFailure是直接修改自身是否能运行来达到这一目的。与之相反的另一个Decorator是ReturnSuccess
public class ReturnFailure : Decorator
{
// The status of the child after it has finished running.
private TaskStatus executionStatus = TaskStatus.Inactive;
public override bool CanExecute()
{
// Continue executing until the child task returns success or failure.
return executionStatus == TaskStatus.Inactive || executionStatus == TaskStatus.Running;
}
public override void OnChildExecuted(T