I don't think i spawn a background thread. I'm using the CouchModel
save method when generating and saving those documents. Using
CouchModel, i couldn't have access to completion block... i would need
to use the non-couchmodel to save the documents.
additional info, i'm also using singleton pattern when i init the
database, like this:
+(DBManager *)singleton {
static dispatch_once_t pred;
static DBManager *shared = nil;
dispatch_once(&pred, ^{
shared = [[DBManager alloc] init];
});
return shared;
}
On Jan 14, 12:49 am, Jens Alfke <
j...@couchbase.com> wrote:
> On Jan 13, 2012, at 9:32 AM, Putra wrote:
>
> I have one button. If it is pressed, it will generate some records
> (documents) in touchDB database.
>
> It sounds like it generates these in the background without blocking the UI, since you can press the button while it’s running. Are you spawning a background thread to create the documents? And what API are you calling on that thread?
>
> (I don’t think this is directly related to your problem, but be aware that CouchCocoa is not thread-safe, meaning that a single CouchCocoa object tree — server, databases, documents, etc. — should only be used on one thread at a time. In other words, create a new CouchServer instance for each thread.)
>
> The problem is that when i press that button, and while it has not
> finished generating the records, i then quickly repress or press again
> the button, my app generates error:
>
> 2012-01-14 00:24:23.130 Imunisasi[9123:707] The FMDatabase
> <FMDatabase: 0x270860> is currently in use.
>
> Please post a backtrace. In fact, a full thread dump would be good here. When Xcode drops into the debugger due to the uncaught exception, go to the debugger console view and enter “thread apply all bt”, then copy and paste the output. Since it’s likely to be lengthy, why don’t you file it in a bug report<
https://github.com/couchbaselabs/TouchDB-iOS/issues/new> instead of posting it here.