Question about using in rust #112
-
#[tokio::main]
async fn main() {
let handle = tokio::spawn(async {
evaluate().await;
});
let handle2 = tokio::spawn(async {
evaluate().await;
});
let (result, result2) = tokio::join!(handle, handle2);
}
async fn evaluate() {
let decision_content: DecisionContent = serde_json::from_str(include_str!("jdm_graph.json")).unwrap();
let engine = DecisionEngine::default();
let decision = engine.create_decision(decision_content.into());
let result = decision.evaluate(&json!({ "input": 12 })).await;
}I am trying to studying this project and I and faced some problem when I try it. Then I compile the above code, I got May I know how to sove this? Great thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Hi @cheunglok97, ZEN expressions are optimized for single-threaded use and don't support multi-threading in the evaluation of a single expression. This limitation applies to the ZEN engine as well. To integrate ZEN decisions within a Tokio-based, multi-threaded environment, you can use Let me know if this solves your issue. |
Beta Was this translation helpful? Give feedback.
Hi @cheunglok97,
ZEN expressions are optimized for single-threaded use and don't support multi-threading in the evaluation of a single expression. This limitation applies to the ZEN engine as well.
To integrate ZEN decisions within a Tokio-based, multi-threaded environment, you can use
Handle::current().block_onto execute these decisions synchronously within an asynchronous context. This approach bypasses Tokio's thread safety requirements for asynchronous functions, allowing you to include non-thread-safe ZEN operations in your Tokio application. For a practical implementation, see this GitHub example.Let me know if this solves your issue.