Skip to main content

@condition

The @condition decorator is used to mark the condition method in a condition block. That method is invoked when the condition block wants to verify if a condition is valid or not. It allows synchronous and asynchronous operation. When synchronous operation is used the decorator method should return true when the condition is valid or false when the condition is invalid. When asynchronous operation is used, the method should return the callback property of the props argument. When the condition operation completes, the result should be passed to callback.return (see example below).

info

It can be used to decorate a method in a ConditionBlock derived class.

tip

Read more about conditions in the Block conditions guide.

Decorator type

Method ℹ️

Applies to

Decorator signature

@condition

Decorated method signature

(props?: {
callback: Callback<boolean>;
}): boolean | Callback<boolean>;

Decorated method parameters

NameTypeOptionalDescription
propsobjectYesSpecifies the properties for the condition method. Contains the following properties:
- callback: Reference to the Callback instance. Pass this reference as method return value to enable the asynchronous condition callback.

Return value

Returns true if the condition is valid, false when the condition is invalid, or props.callback to indicate asynchronous operation.

Example

Synchronous example:

import { tripetto, condition, ConditionBlock, Callback } from "@tripetto/runner";

@tripetto({
type: "condition",
identifier: "example-condition-block",
})
class ExampleConditionBlock extends ConditionBlock {
@condition
isValid(): boolean {
// Indicate the condition is valid
return true;
}
}

Asynchronous example:

import { tripetto, condition, ConditionBlock, Callback } from "@tripetto/runner";

@tripetto({
type: "condition",
identifier: "example-condition-block",
})
class ExampleConditionBlock extends ConditionBlock {
@condition
isValid({ callback }: { callback: Callback<boolean> }): Callback<boolean> {
setTimeout(() => {
// After a while, indicate the condition is invalid
callback.return(false);
}, 1000);

return callback;
}
}