0

how would I do this:

@MainActor class Foo {}
class Bar: Foo {
    func caller()
    {
    // how would I invoke somethingIneedToRunOnThreadOtherThanMain so that it runs on thread other than main?
    }

    func somethingIneedToRunOnThreadOtherThanMain() async throws
    { ...
    }


}
Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66
  • 1
    This was closed before I could add an answer. In a playground I got this to work by using `nonisolated func somethingIneedToRunOnThreadOtherThanMain() async throws {` and calling it inside a Task within `caller`: `try await somethingIneedToRunOnThreadOtherThanMain()`. The task did not need to be detached for the other method to be run off the main actor. – Geoff Hackworth Apr 12 '23 at 14:59
  • Thanks! Apparently I was a @ removal away from that solution – Anton Tropashko Apr 12 '23 at 15:01
  • This answer is very helpful: https://forums.swift.org/t/determining-whether-an-async-function-will-run-on-the-main-actor/60749/2 Basically async methods will run in the background no matter where they are called from unless they are isolated to the main actor. – Geoff Hackworth Apr 12 '23 at 15:02

0 Answers0