0

我们想异步调用一个长时间运行的活动,并且在基于外部信号的某个时间后,想取消该长时间运行的活动。

Async.procedure(activities::longRunningActivity)
// Execute some synchronous activities
Workflow.await(() -> !messageQueue.isEmpty());
if (messageQueue.remove(0) == "something") {
    // Cancel longRunningActivity
}

目前,活动了解取消的唯一方法是通过心跳。确保您的活动心跳并且不会吞下心跳方法抛出的异常。

4

1 回答 1

0

使用CancellationScope

  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();
  }
于 2020-06-20T15:00:26.160 回答