Post

Replies

Boosts

Views

Activity

Actor URLSession Warning?
Non-sendable type '(any URLSessionTaskDelegate)?' exiting actor-isolated context in call to non-isolated instance method 'data(from:delegate:)' cannot cross actor boundary Please help, I am 1000% stuck on this issue in particular. Using strict asynchronous warnings, how can I make this work without warning? I can convert NetworkManager into a struct, but I prefer to keep it as an actor so that it is Sendable by default.
4
0
2.6k
Dec ’23
Have 2 Task with for loops run concurrently?
Say I want to run a Task, with a for loop. Then have another Task with a for loop. And have these both run concurrently. Is there a way? I tried doing this: func stepAsyncStep(id: String, number: Int) async { if number % 10000 == 0 { print("chirp \(id) @ \(number)") } } func somethingAsync(id: String) async { for i in 0...100_000 { await stepAsyncStep(id: id, number: i) } } Task.detached { print("task a begin") await somethingAsync(id: "a") print("task a end") } Task.detached { print("task b begin") await somethingAsync(id: "b") print("task b end") } task a begin chirp a @ 0 chirp a @ 10000 chirp a @ 20000 chirp a @ 30000 chirp a @ 40000 chirp a @ 50000 chirp a @ 60000 chirp a @ 70000 chirp a @ 80000 chirp a @ 90000 chirp a @ 100000 task a end task b begin chirp b @ 0 chirp b @ 10000 chirp b @ 20000 chirp b @ 30000 chirp b @ 40000 chirp b @ 50000 chirp b @ 60000 chirp b @ 70000 chirp b @ 80000 chirp b @ 90000 chirp b @ 100000 task b end The only way I can make these run in parallel is to add sleeps into the loops. Is there any way to make then run concurrently without Task.sleep ? I also tried a TaskGroup, this doesn't work either. Crying for help here.
2
0
572
Mar ’23