TimerTask interface
從 DurableClient傳回。如果呼叫不是 createTimer(Date)-ed,yield。 表示擱置的定時器。 如需詳細資訊,請參閱 工作 檔。
所有擱置定時器都必須完成或取消,協調流程才能完成。
範例
取消定時器
// calculate expiration date
const timeoutTask = context.df.createTimer(expirationDate);
// do some work
if (!timeoutTask.isCompleted) {
// An orchestration won't get marked as completed until all its scheduled
// tasks have returned, or been cancelled. Therefore, it is important
// to cancel timers when they're no longer needed
timeoutTask.cancel();
}
範例
建立逾時
const now = Date.now();
const expiration = new Date(now.valueOf()).setMinutes(now.getMinutes() + 30);
const timeoutTask = context.df.createTimer(expirationDate);
const otherTask = context.df.callActivity("DoWork");
const winner = yield context.df.Task.any([timeoutTask, otherTask]);
if (winner === otherTask) {
// do some more work
}
if (!timeoutTask.isCompleted) {
// An orchestration won't get marked as completed until all its scheduled
// tasks have returned, or been cancelled. Therefore, it is important
// to cancel timers when they're no longer needed
timeoutTask.cancel();
}
- Extends
屬性
| cancel | 表示應該取消定時器。 此要求會在下一個 |
| is |
繼承的屬性
| is |
工作是否已完成。 請注意,完成不等於成功。 |
| is |
工作是否因為錯誤而發生錯誤。 |
| result | 如果已完成,則為工作的結果。 否則 |
屬性詳細資料
cancel
表示應該取消定時器。 此要求會在下一個 yield 或 return 語句上執行。
cancel: () => void
屬性值
() => void
isCanceled
isCanceled: boolean
屬性值
boolean
是否已取消定時器。