A followup question:

I can't use [CBLManager sharedInstance] because I'm calling [CBLManager 
initWithDirectory:options:error: ] to specify a directory.

I call this from two different objects, both on the main thread but doing 
separate work. One of them, however, passes a CBLModel acquired from the 
CBLDatabase to an NSOperation subclass to do some work on a background 
NSOperationQueue. I'm guessing this is going to cause me some problems.

So, questions:
1. Will using two different copies of CBLManager in two different objects on 
the main thread cause issues? If so, any suggestions on how to make it work?
2. Assuming that passing the CBLModel to the NSOperation is a bad idea, would 
the solution be to pass the docID to the NSOperation and have it call 
[CBLManager initWithDirectory:options:error: ] on it's own thread? Would that 
be safe?

Thanks!


On Apr 19, 2014, at 2:49 PM, Jens Alfke <[email protected]> wrote:

> 
> On Apr 19, 2014, at 11:42 AM, Ragu Vijaykumar <[email protected]> wrote:
> 
>> I was wondering how to properly use CBL both in the main thread and 
>> background thread to the same database. Should I instantiate a CBLManager 
>> both in the main thread ([CBLManager sharedInstance]) and background thread 
>> ([[CBLManager sharedInstance] copy]) and then basically treat the two as if 
>> they were running in separate programs (each using their own CBLModels, 
>> etc.) with no sharing between the two?
> 
> Exactly. Basically, those classes are not thread-safe. However, the database 
> file itself is thread-safe.
> 
>> If I share the docIDs (NSStrings) between the threads, do I just make a 
>> CBLDocument with the docID and CBLModel with the CBLDocument in both threads 
>> and operate that way?
> 
> Yes.
> 
> Also, if you listen for change notifications, they will tell you about 
> changes made by other threads. So if you write your UI code so that the 
> controllers are driven by change modifications and update the views 
> accordingly, then it will Just Work.
> 
> --Jens
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Couchbase Mobile" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/mobile-couchbase/3A5867E8-B1E6-4233-B7A1-18BD00F0F46B%40couchbase.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/9EAF9D96-8DED-43A8-B955-441340DE9935%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to