No, that's not what I mean. Let's look at an analogy to old-fashioned synchronous code:
func run2() { print("Hello") }
func run1() { run2() }
run1()
The call stack for this synchronous code is as follows:
- thread -> run1() -> run2() -> print()
We can say that starting with run1()
, then going to run2()
, etc. all this code is executed in a single thread.
Now take the following async code:
func run2() async { print("Hello") }
@MainActor
func run1() async { await run2() }
Task {
await run1()
}
The call stack for this asynchronous code is as follows:
- task -> run1() -> run2() -> print()
In a similar way we can say that starting with run1()
, then going to run2()
, etc. all this code is executed in a single task.
The additional complexity of functions that must run on specific executors is orthogonal to this concept.