3

Having an NSManagedObjectContext with concurrency type NSPrivateQueueConcurrencyType can PromiseKit be used to prettify the performBlock:^{} / performBlockAndWait:^{} ?

My first thought was to write like this :

- (PMKPromise *)updateModel:(Model *)model
{
    return [PMKPromise new:^(PMKPromiseFulfiller fulfill, PMKPromiseRejecter reject) {
        [_managedContenxtModel performBlock:^{
                //...
                fulfill(...)
        }];
    }];
}

but, I'm afraid that because the promise block will be registered in a DISPATCH_QUEUE_CONCURRENT and if multiple calls to updateModel:, from different threads, are made it can't guarantee that the blocks from the performBlock are registered in the correct order.

Is there a change that this can happen ?
What about using performBlockAndWait:^{} instead ?

Daniel
  • 1,225
  • 2
  • 15
  • 31

1 Answers1

1

You could use dispatch_promise_on with a concurrent queue you create yourself:

- (PMKPromise *)updateModel:(Model *)model
{
    return dispatch_promise_on(myQ, ^{
        [_managedContenxtModel performBlockAndWait:^{
                //...
        }];
        fulfill(...)
    }];
}

If this doesn't answer your question, let me know and I'll try to help further.

mxcl
  • 26,392
  • 12
  • 99
  • 98