0

i would like to execute my couchbase operations on a dedicated dispatch queue within Swift. I adapted the code from this couchbase-example plus adding function calls referencing to self. within in the dispatch closure. At this point my application freeze. I attached [unowned self] to my closure because i thought it has of a strong reference to self but that doesn't help. What am i doing wrong here?

couchbase-lite-ios-1.0.0, XCode6 Version 6.0 (6A313)

public class MYDao {

   private var manager : CBLManager!
   private var dispatchQueue : dispatch_queue_t!

   public init(){
      //Retrieve copy of CBLManager
      self.manager = CBLManager.sharedInstance().copy()

      //Create dedicated db queue
      self.dispatchQueue = dispatch_queue_create("com.myapp.db", DISPATCH_QUEUE_SERIAL)

      //Assign db queue to manager
      self.manager.dispatchQueue = self.dispatchQueue
   }


   public func getDb() -> CBLDatabase {
        var database : CBLDatabase?

        //Dispatch self.manager operation on db queue
        dispatch_sync(self.dispatchQueue, {[unowned self] in
            //FREEZE
            database = self.manager.existingDatabaseNamed("mydb", error: nil)
        })

        return database;   
   }    
} 
robbiebubble
  • 161
  • 9
  • This looks like a deadlock to me. What does `self.manager.existingDatabaseNamed` look like? Is it using `manager.dispatchQueue` somehow? – Mike S Sep 19 '14 at 20:34
  • Doesn't seems like [CBLManager.m](https://github.com/couchbase/couchbase-lite-ios/blob/master/Source/API/CBLManager.m#L399) is using it's internal dispatchQueue – robbiebubble Sep 20 '14 at 08:53
  • Are you using latest couchbase version3? – Rajeev Oct 13 '14 at 10:23
  • I'm getting the same deadlock issue, on the latest couchbase-lite-ios version. Have you created a github issue? – Erich Oct 13 '14 at 21:51
  • @Erich i've posted the same question in the couchbase lite mobile google group: [Swift Couchbase Lite CBLManager dispatch_queue](https://groups.google.com/forum/#!topic/mobile-couchbase/x1uzJdSYutg). They recommend to "upgrade" but i didn't had the time to verify it with 1.0.2. – robbiebubble Oct 14 '14 at 07:05
  • @robbiebubble my issue is somewhat resolved on 1.0.2. I get the console error "database busy" and a slight pause, but no deadlock. I was previously using a self-compiled version of their most recent git commit, so there must've been a regression. – Erich Oct 14 '14 at 14:38

0 Answers0