infinitered / cdq

Core Data Query for RubyMotion
MIT License
172 stars 35 forks source link

Disappearing context #126

Closed jelmerderonde closed 8 years ago

jelmerderonde commented 8 years ago

I'm using RedPotion 1.5.0 which includes CDQ 1.0.8 and the latest version of the AWS SDK which includes (a renamed version of) the Bolts framework.

In my Project < CDQManagedObject class the entire CDQ stack seems to vanish after a Bolts succes block. I will include a little bit of code to illustrate:

class Project < CDQManagedObject

...
      def fetch
            get_project(self.parse_object_id).continueWithSuccessBlock(lambda do |task|
                  @project = task.result
                  self.title = @project['title']
                  self.key = @project['key']
                  self.size = @project['size']

                  app.data.save

                  mp "1:"
                  mp app.data.contexts.current
                  return download_package(self.key)
                end).continueWithSuccessBlock(lambda do |task|
                  mp "2:"
                  mp app.data.contexts.current
      end
...
end

Output of this is: "1:" #<NSManagedObjectContext:0x112c34ac0> "2:" nil

Maybe I'm doing something colossally wrong but I can't get it fixed. I would appreciate any help.

kemiller commented 8 years ago

Can you tell what thread they are running on?

kemiller commented 8 years ago

Also, what does it mean to have more than one success block?

jelmerderonde commented 8 years ago

Using NSThread.currentThread the app.data.contexts.current's appear to be on different threads.

jelmerderonde commented 8 years ago

in the first succesblock I return a new task. If that is also succesful the next block is called.

kemiller commented 8 years ago

If you're on a new thread, it won't have a context stack set up. Some info here: https://github.com/infinitered/cdq/wiki/New-Threading-and-Context-Stack-model