What is the mechanism by which workflow tasks know which code to run?

What is the mechanism by which workflow tasks know which code to run?

For example, IIUC, all of the following would dictate that certain parts of the workflow definition would run. In these cases, how does the SDK/temporal know which code to run?

  • when an awaited activity result gets completed
  • when a workflow gets cancelled
  • when a signal is received
  • when a condition unblocks
  • when a timer fires

As a related question, is there an internal list of awaited tasks that need to be checked at certain points? I believe this is a sort of internal/custom event loop within the SDKs. And if so, when does that list get checked? My suspicion is that it gets checked (and runs any unblocked tasks) just before a workflow task would otherwise be completed. For example, processing a signal may unblock an condition, and the task associated with the unblocked condition would run in the same workflow task as the signal processing.

The SDK maintains mapping between each abstraction and the corresponding awaitable.
When a workflow task with new events is received then all the correspondent awaited tasks are resolved. Then workflow tries to run all the available threads/goroutines/coroutines. The ones that have their awaited tasks resolved proceed executing. The execution can unblock some other tasks. The workflow task is done when none of the workflow threads/goroutines/coroutines is able to make any progress.

1 Like