# Is nonisolated(nonsending) on a function \*parameter\* mostly useless?

**URL:** <https://forums.swift.org/t/is-nonisolated-nonsending-on-a-function-parameter-mostly-useless/86649>\
**Category:** Using Swift\
**Tags:** concurrency\
**Created:** [May 11, 2026, 1:49pm UTC](https://forums.swift.org/t/is-nonisolated-nonsending-on-a-function-parameter-mostly-useless/86649 "2026-05-11T13:49:32Z")\
**Posts on this page:** 1\
**Showing post:** 23

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [May 12, 2026, 7:44am UTC](https://forums.swift.org/t/is-nonisolated-nonsending-on-a-function-parameter-mostly-useless/86649/23 "2026-05-12T07:44:41Z")

</div>

> [@bjhomer](#):
>
> ```swift
> func doit() async {
> let dbContext = persistentContainer.newBackgroundContext()
> let contextActor = ContextActor(context: dbContext)
> 
> contextActor.performAsyncBlock {
> // Insert a new 'Person' into the dbContext. It would be
> // a runtime error to call this from the wrong thread, which
> // is why I need `performAsyncBlock` to ensure that it runs
> // on the correct context.
> let person = Person(context: dbContext)
>     
> // Do something asynchronous
> let present = await fetchPresent()
> 
> // Here I am, synchronously calling a function on my 
> // database object. No 'await' needed'
> person.haveBirthday(gift: present)
> 
> try! dbContext.save()
> }
> }
> 
> ```

I'm not familiar with CoreData. There was a thread about a special behavior of `ModelActor` in [this thread](https://forums.swift.org/t/question-about-swiftdata-and-concurrency-interoperability/83097), though that behavior is invisible to type system so I guess it's irrelevant. That said, `person` is created inside the closure so it can be accessed synchronously of course. I'm glad the `sending` hack works for you.

FWIW, I haven't been able to reproduce the issue using regular actors. The following code produces diagnostic rather than compiles with misbehavior. This is the same issue as demonstrated by `isolatedToGlobalActor` in [another thread](https://forums.swift.org/t/isolated-closures-and-concurrent-functions/86614).

```swift
actor DBActor {
  func run(_ work: nonisolated(nonsending) () async -> Void) async {
    await work()
  }
}

class DBObject {
    func modify() {}
    func save() {}
}

// Note: the code compiles if `buttonPushed` is nonisolated.
@MainActor func buttonPushed() {
    let myDatabaseActor = DBActor()
    Task {
        await myDatabaseActor.run { // error: sending value of non-Sendable type '() async -> Void' risks causing data races [#RegionIsolation::SendingRisksDataRace]
            print("\(#isolation as (any Actor)?)")
      	    let dbObject = DBObject()
            dbObject.modify()
            dbObject.save()
        }
    }
}

```

---

_[View the full topic](https://forums.swift.org/t/is-nonisolated-nonsending-on-a-function-parameter-mostly-useless/86649)._
