The code you posted got squished onto one line and isn’t readable.
Did you already ask this question on the Couchbase forums? It sounds familiar. My answer there was that changes won’t be visible to other threads (which have their own database connections) until the transaction is committed.
Unfortunately, the transaction doesn’t commit until just after your async block returns, so a notification or other callout from your block will run too early. This looks like a limitation in our API; it totally makes sense that you’d want to schedule something to be called after the background operation completes.
As a workaround, I think issuing a delayed-perform at the end of the block will work. This will run on the background thread but after the transaction has been committed, so at that point you can notify the main thread.
// … make changes to documents…
NSRunLoop.defaultRunLoop.performBlock {
ThreadController.performBlockOnMainQueue{ completionClosure?()}
}
—Jens