Passing values to an Task/Actor in serial manner

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.

Okay, sure, I've just never heard it described that way, since that's how all functions work. This seems like another instance where I'm not seeing usefulness of the statement. Thanks for indulging me so far.

I did not want to disturb your discussion earlier. Thank you for all responses, all clear now :)

2 Likes