Is the Diffable DataSource queue created on whatever thread it we created the datasource on?

285 Views Asked by At

I'm trying to understand diffabledata source threading in more detail.

In my code I create a diffable data source on the main thread.

This data source uses a backing storing.

The data for the backing store comes from the following getter method.

    var getData: [MyDataType] {
        get {
            //Sometimes this prints MainThread and sometimes it prints com.apple.uikit.datasource.diffing
            LOG.DLog("Returning Data On \(currentQueueName())")
      
            if Thread.isMainThread {
                return _myDataValues
            } else {
                //This else statement never enters
                return DispatchQueue.main.sync {
                    LOG.DLog("Returning Data On Main")
                    return _myDataValues
                }
            }
        }
    }
   func currentQueueName() -> String {
            let name = __dispatch_queue_get_label(nil)
            guard let str = String(cString: name, encoding: .utf8) else { return ""}
            return str
        }

When my get method executes, sometimes the queue name is com.apple.uikit.datasource.diffing and sometimes the queue name is Main.

In the case where the queue name is com.apple.uikit.datasource.diffing I would expect my else condition to enter but it never does.

So my question is, why does the else condition in my code example ever enter? My best guess is that the diffable serial queue is created on the same thread that the diffable datasource was created on.

0

There are 0 best solutions below