Post

Replies

Boosts

Views

Activity

Comment on Task on MainActor does not run on the main thread, why?
THANKS! Yes, it seems that the devil must be in some detail. The swift doc says: "To create an unstructured task that runs on the current actor, call the Task.init(priority:operation:) initializer." And I am really curious, why task created in main() with inferred @MainActor (I have read that this static function has @MainActor inferred, when it is in the @main struct) does not all run on the main thread. I am puzzled.
Jul ’22
Comment on Task on MainActor does not run on the main thread, why?
Statement: "Swift makes no guarantee that the thread which executed the code before the await is the same thread which will pick up the continuation as well." Questions: Do I understand right that when the explicit async context is MainActor (Task closure is annotated by @MainActor), then it is guaranteed that the thread used for continuation (after await) will be the main thread? Is this guaranteed also for inherited MainActor async context?
Jul ’22
Comment on Swift concurrency and NSData - all threads stuck in mach_msg2_trap
Resolved. Threads are blocked by filesystem operations.
Replies
Boosts
Views
Activity
Mar ’24
Comment on Task on MainActor does not run on the main thread, why?
task2 is created as detached, so does NOT inherit the main actor async context, so it is correct not to run on the main thread. The example above was misleading.
Replies
Boosts
Views
Activity
Jul ’22
Comment on Task on MainActor does not run on the main thread, why?
THANKS! Yes, it seems that the devil must be in some detail. The swift doc says: "To create an unstructured task that runs on the current actor, call the Task.init(priority:operation:) initializer." And I am really curious, why task created in main() with inferred @MainActor (I have read that this static function has @MainActor inferred, when it is in the @main struct) does not all run on the main thread. I am puzzled.
Replies
Boosts
Views
Activity
Jul ’22
Comment on Task on MainActor does not run on the main thread, why?
Statement: "Swift makes no guarantee that the thread which executed the code before the await is the same thread which will pick up the continuation as well." Questions: Do I understand right that when the explicit async context is MainActor (Task closure is annotated by @MainActor), then it is guaranteed that the thread used for continuation (after await) will be the main thread? Is this guaranteed also for inherited MainActor async context?
Replies
Boosts
Views
Activity
Jul ’22