I understand that temporal workflows ensure that only a single thread of execution can be active at a given time, and that once a thread blocks, execution can switch to another thread that is ready to execute.
I want to make sure I understand the conditions where a thread of execution may yield to another thread of execution. Workflow.await(), Workflow.sleep(), blocking on promise completion, etc can block and yield, but what about operations like Workflow.newTimer() or Workflow.newPromise()? These don’t need to block but I’m assuming that Workflow.newTimer() does need to register its timer with the temporal server, which would require an RPC. Does this interaction with the server also cause the current thread to yield execution, potentially allowing other threads to execute before Workflow.newTimer() returns? Or can I assume that Workflow.newTimer() and similar methods will never yield?
Yes, that is my hope, but I don’t think that response confirms that no other methods yield.
I think it’d be helpful to get a stronger confirmation of this in the documentation.
Relevant part of the response you link to (to make it easy for others to see what is being referenced):
Only one thread is executed at a time and switch to another thread can happen only when a blocking operation using Temporal provided primitives is called. Examples of such operations are Workflow.sleep, Promise.get, Workflow.await. As no blocking operations are called between this.jobQueue.size() > 0 and Workflow.continueAsNew(this.jobQueue); lines, no other thread can intervene.
For now I’m taking a defensive approach and assuming other methods can yield as well.