我们想异步调用一个长时间运行的活动,并在一段时间后根据外部信号,想取消该长时间运行的活动。
Async.procedure(activities::longRunningActivity)
// Execute some synchronous activities
Workflow.await(() -> !messageQueue.isEmpty());
if (messageQueue.remove(0) == "something") {
// Cancel longRunningActivity
}
当前,一项活动了解取消的唯一方法是通过心跳。确保您的活动心跳正常,并且不会吞下心跳方法引发的异常。
答案 0 :(得分:0)
CancellationScope longRunningCancellationScope =
Workflow.newCancellationScope(
() -> Async.procedure(activities::longRunningActivity));
longRunningCancellationScope.run();
// Execute some synchronous activities
Workflow.await(() -> !messageQueue.isEmpty());
if (messageQueue.remove(0) == "something") {
longRunningCancellationScope.cancel();
}