# Is that OK to created a modelContext inside an async func?

**URL:** <https://forums.swift.org/t/is-that-ok-to-created-a-modelcontext-inside-an-async-func/82772>\
**Category:** Using Swift\
**Tags:** swiftdata\
**Created:** [October 21, 2025, 7:04am UTC](https://forums.swift.org/t/is-that-ok-to-created-a-modelcontext-inside-an-async-func/82772 "2025-10-21T07:04:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SecondOpion](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@SecondOpion](https://forums.swift.org/u/SecondOpion)\
**Post date:** [October 21, 2025, 7:04am UTC](https://forums.swift.org/t/is-that-ok-to-created-a-modelcontext-inside-an-async-func/82772/1 "2025-10-21T07:04:20Z")

</div>

The modelContext is not Sendable, when I have an async func, such like download data from Internet, I can't pass the modelContext as parameter, the compiler complaints said it causes data race.

So I shared the modelContainer globally, then create the modelContext inside the async func, complier seems fine with that, and everything works.

But I still worry is that OK, any concerns, what's the best practice for that?
