Is Task.detached still useful?

Yeah task executors are great but they do more than you described here. They affect the entire task hierarchy of the task which has a task executor configured (!), since their purpose is to keep all those tasks executing on the same executor.

This is different than just “enqueue this one task on specific executor”.

The reason we don’t have Task(on: some serial executor) is because of the long term goal to spell this as Task { [isolated <some serial executor>] in } which would work better with compile time isolation checking. However, we don’t have this spelling because we’re missing this language feature closure isolation control.

So yes, detached captures many semantics, but we don’t have a real replacement for some of them yet.

3 Likes