Adding geometry asynchronously [do work in background thread]

Hey, I'm wondering what would be the proper way to add RealityView content asynchronously, while doing the heavy lifting in a background thread. My use case is that I am generating procedural geometry which takes a few seconds to complete. Meanwhile I would like the UI to show other geometry / UI elements and the Main thread to be responsive.

Basically what I would like to do, in pseudocode, is:

runInBackgroundThread {
  let geometry = generateGeometry() // CPU intensive, takes 1-2 s
  let entity = createEntity(geometry) // CPU intensive, takes ~1 s
  let material = try! await ShaderGraphMaterial(..)
  entity.model!.materials = [material]

  runInMainThread { 
    addToRealityViewContent(entity)
  }
}

With this I am running into so many issues with especially the material, which apparently cannot be constructed on a non-main thread and cannot be passed over thread borders.

Adding geometry asynchronously [do work in background thread]
 
 
Q