# Question about @MainActor

**URL:** <https://forums.swift.org/t/question-about-mainactor/49600>\
**Category:** Using Swift\
**Created:** [June 14, 2021, 6:01pm UTC](https://forums.swift.org/t/question-about-mainactor/49600 "2021-06-14T18:01:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morten\_Bek\_Ditlevsen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/morten_bek_ditlevsen/32/28133_2.png) [@Morten\_Bek\_Ditlevsen](https://forums.swift.org/u/Morten_Bek_Ditlevsen)\
**Post date:** [June 14, 2021, 6:01pm UTC](https://forums.swift.org/t/question-about-mainactor/49600/1 "2021-06-14T18:01:29Z")

</div>

When trying to call a method on a class marked as running on the MainActor from within a background DispatchQueue, I correctly get a compiler error, which goes away when calling it from DispatchQueu.main.async { … }. Also fine and expected.

But what is the mechanism that allows the compiler to diagnose this?

I just skimmed the API diffs for DispatchQueue, and so didn’t spot anything related to the MainActor.

Would something similar be implemented for third party libraries like RxSwift?

---

<div class="post-metadata">

**Author:** ![benlings](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/benlings/32/13011_2.png) [@benlings](https://forums.swift.org/u/benlings)\
**Post date:** [June 14, 2021, 7:00pm UTC](https://forums.swift.org/t/question-about-mainactor/49600/2 "2021-06-14T19:00:17Z")

</div>

I'm sure I either read something about this on the forums or saw it in a WWDC session, but now can't find it. I took a look through the compiler source and found this:

[https://github.com/apple/swift/commit/b68f8555b31cd8dd242a6a70b2fc6c5ea014cae5](https://github.com/apple/swift/commit/b68f8555b31cd8dd242a6a70b2fc6c5ea014cae5)

Looks like `DispatchQueue.main.async` is special-cased to infer that it is `@MainActor`.

---

<div class="post-metadata">

**Author:** ![Morten\_Bek\_Ditlevsen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/morten_bek_ditlevsen/32/28133_2.png) [@Morten\_Bek\_Ditlevsen](https://forums.swift.org/u/Morten_Bek_Ditlevsen)\
**Post date:** [June 14, 2021, 7:43pm UTC](https://forums.swift.org/t/question-about-mainactor/49600/3 "2021-06-14T19:43:39Z")

</div>

Excellent! Thanks a lot! 😊
