I am currently using Swift 5.5
No, despite adding an iboutlet, or modify my ViewController update stay on generic thread
Thank you for this, it was a very interesting read, I understand that we have a problem with the current design of concurrency and the understanding of it :/ and its predictability
FYI:
I found two ways to fix my issue :
1. Adding async to my @MainActor function :
@MainActor func update() async
output :
simpleFunction thread : <_NSMainThread: 0x6000001286c0>{number = 1, name = main}
launch Task thread : <_NSMainThread: 0x6000001286c0>{number = 1, name = main}
In Do Task thread : <_NSMainThread: 0x6000001286c0>{number = 1, name = main}
longAsyncWork thread : <NSThread: 0x60000011fc00>{number = 6, name = (null)}
In catch Task thread : <_NSMainThread: 0x6000001286c0>{number = 1, name = main}
simpleFunction thread : <_NSMainThread: 0x6000001286c0>{number = 1, name = main}
update thread : <_NSMainThread: 0x6000001286c0>{number = 1, name = main}
But my Task {} it's now called on MainThread O_o
2. Specify ViewController as @MainActor
output:
simpleFunction thread : <_NSMainThread: 0x600003e0c740>{number = 1, name = main}
launch Task thread : <_NSMainThread: 0x600003e0c740>{number = 1, name = main}
In Do Task thread : <_NSMainThread: 0x600003e0c740>{number = 1, name = main}
longAsyncWork thread : <NSThread: 0x600003e5c040>{number = 4, name = (null)}
In catch Task thread : <_NSMainThread: 0x600003e0c740>{number = 1, name = main}
simpleFunction thread : <_NSMainThread: 0x600003e0c740>{number = 1, name = main}
update thread : <_NSMainThread: 0x600003e0c740>{number = 1, name = main}
In same way inside my Task {} i am in MainThread and it's really weird for me, but I suspect it's an optimization to minimize jump between thread ? I am right ?
@John_McCall What is the right option for you?
Thanks to all for your help 