dispatch_queue_t couchbase_queue = dispatch_queue_create("COUCHBASE_TRANSACTION_QUEUE", DISPATCH_QUEUE_SERIAL);
[CBLManager sharedInstance].dispatchQueue = couchbase_queue;
dispatch_async(couchbase_queue, ^{
CBLView *view = [[self get].database viewNamed:@"commentsByReport"];
CBLLiveQuery *query = [[view createQuery] asLiveQuery];
query.keys = @[ report_id ];
dispatch_async(dispatch_get_main_queue(), ^{
[_commentsQuery addObserver:self forKeyPath:@"rows" options:0 context:0];
});
});
[[_database viewNamed:@"commentsByReport"] setMapBlock: MAPBLOCK({
if ([doc[@"type"] isEqualToString: @"comment"]) {
if (doc[@"_deleted"]) { return; }
emit(doc[@"report_id"], doc);
}
}) reduceBlock: nil version: @"1.13"];
dispatch_async(couchbase_queue, ^{
CBLView *view = [[self get].database viewNamed:@"commentsByReport"];CBLLiveQuery *query = [[view createQuery] asLiveQuery];
query.keys = @[ report_id ];
dispatch_async(dispatch_get_main_queue(), ^{
[_commentsQuery addObserver:self forKeyPath:@"rows" options:0 context:0];
});
});
We have tried registering the _commentsQuery for KVO on the couchbase_queue, but then it doesn't even return the initial set.
Ah, I see. I actually thought at one point it might be related to the impermanent nature of dispatch_queues - but I couldn't find a good way to persist the dispatch queue on a particular thread.
Is there a way to associate a particular NSThread object with the CBLManager instance instead of a GCD queue? If not, I'll probably checkout the latest commits an attempt the change myself, just for expediency. Thanks for your help!