last day (16 days later) » 

15:57
Hi
 
2 hours later…
17:37
Hey
Thanks for reaching out
You say
```
async let = is a structured concurrency, it does not inherit actor async context. I also wrote Detached tasks Task.detached, async let = tasks, group tasks do NOT inherit actor async context.
The key point, not too much discussed anywhere, is the fact that child task and async context inheritance are two separate topics.
So here comes my confusion after reading a few books and numerous articles on the topic - What exactly do we mean when we say "async context" ? Is this the Sendable closure used in the Task initializer, is this the magical place where actor isolation happens in ?
Following from here stackoverflow.com/a/71577170/483375 can I safely assume that when we talk about child task this is the implicit creation (user has no notion of Task creation at this point) of task when using async let or a task group - are there other cases that can create a child task ?
18:18
On the same topic - I keep seeing examples where we create a Task inside an async function and I don't get it - creating a Task (unstructured concurrency) should be happening only in sync functions right ?
18:46
Furthermore in the reference about Task it is stated "To support operations on the current task, which can be either a detached task or child task, Task also exposes class methods like yield(). Because these methods are asynchronous, they’re always invoked as part of an existing task." - "support operations on the current task ... which can be child task" -> given that we said that a child task is one implicitly created with async let or task group - how do I even make operation on a child task?
18:59
Async context is an environment, where calling await is possible
async context is created by Task initializer. However, thisinitializer ca be implicit. Like .task modifier in SwiftUI, or when command line program can have main() async
The difference between child task and task created in another task (read the previous words again!) is just the following: task cannot finish with running child task
Also, task sets isCancelled to its child tasks, not to tasks that are created in the task, but are not child tasks
async let and task group tasks are child tasks
I am not aware of any other way of creating child tasks.
"creating a Task (unstructured concurrency) should be happening only in sync functions right ?" - not neccessarily. You can create another task in task using Task.init or Task.detached. It is just NOT a child task
so, when the original tasks is cancelled, this information is not transferred to the created task, because it is NOT a child task
and, the original task can finish before the other created tasks finishes
the fact, that the task may inherit async context, is just another topic. Keep it separate.
"how do I even make operation on a child task?" ??? - I do not understand. async let something = await thisIsWhatRunsInTheChildTask()
in task group is the child task what you add to the task group
@Sendable closure, or Sendable type marks a type, that can cross async contexts - whith some simplicity it means, that it is thread-safe
has nothing to do with async context
This async/await topic is a difficult one, even Paul Hudson has MANY incorrect statements in his Concurrency tutorial that is freely available.

  last day (16 days later) »