raaj
raaj

Reputation: 3291

Grand Central Dispatch function call

Good Day,

I have a function that is encapsulated in a GCD block, that calls another function that is encapsulated in a GCD block.

Problem is, I need the caller GCD block to stop running, until my function [self callFunction] ends.

I could write another function that doesnt have the gcd encapsulation, but I would prefer not to. Is there any solution?

Thanks

Upvotes: 0

Views: 135

Answers (1)

Anupam
Anupam

Reputation: 556

Since it is a block you can just call the method normally and store the result. Then grab the main queue if you need to update any UI or do whatever you need to after completion.

    dispatch_queue_t queue = dispatch_queue_create("read disc", NULL);
dispatch_async(queue, ^{
   result = [self readDisc];
    dispatch_async(dispatch_get_main_queue(), ^{
      //update UI or do whatever you need to do with the result of readDisc
    });
});
dispatch_release(queue);

Upvotes: 2

Related Questions