rulebook icon indicating copy to clipboard operation
rulebook copied to clipboard

Futures/CompletionStage/Async

Open ktalebian opened this issue 3 years ago • 2 comments

How do you create a role where the condition/evaluation is async? For example, I need to make a HTTP request to verify a fact and return the result.

ktalebian avatar Mar 23 '21 04:03 ktalebian

If you are using something like Spring Boot to accept the HTTP request then you can just create your RuleBook as a Bean and Autowire it into your Controller.

Check out this example: https://github.com/deliveredtechnologies/rulebook/tree/develop/rulebook-examples/helloworld-spring-web

Clayton7510 avatar May 26 '21 15:05 Clayton7510

@Clayton7510 I'm not sure how this applies to my original question. The rule itself needs to be async. In the link you provided, the when condition is still sync https://github.com/deliveredtechnologies/rulebook/blob/develop/rulebook-examples/helloworld-spring-web/src/main/java/com/example/rulebook/helloworld/HelloSpringRule.java

Basically, instead of

@When
public boolean when() {
  return hello != null;
}

I need

@When
public CompletionStage<boolean> when() {
  return getRequest().thenApply(result => result != null);
}

ktalebian avatar Jun 22 '21 22:06 ktalebian