0

If I call invoke on NSInvocation, is it the same as calling performSelector: with the argument waitUntilDone:YES? That is, does invoke block the execution until the called selector is done?

In other words, are the two following code lines exactly the same?

// myInvocation is of type NSInvocation
[myInvocation invoke];
[myInvocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:YES];
nyi
  • 1,425
  • 1
  • 15
  • 17

1 Answers1

3

[NSInvocation invoke] is exactly the same as calling the message that the NSInvocation represents. Like any message call, it will do it on the current thread.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
  • But will it block the execution? I'm asking because of a problem with `NSMutableData.writeToFile:` which is non-blocking. See e.g. http://stackoverflow.com/questions/11161079/nsdata-writetofileatomically-doesnt-immediately-save-the-file – nyi Sep 23 '14 at 14:46
  • 2
    I said it's exactly the same as an ordinary method call. Ordinary method calls are blocking. Calling [someObject doStuff] or creating an invocation and calling [invocation invoke] is _exactly_ the same. – gnasher729 Sep 23 '14 at 14:51
  • Do you have a problem with writeToFile: yourself? The documentation says nothing at all about non-blocking, so I'd assume it is blocking. Especially since for a non-blocking call there would have to be some information how to find out when it's finished, and there is none. Just because someone has problems using it doesn't mean they are right. Being nonblocking would make that method unusable. – gnasher729 Sep 23 '14 at 14:53
  • Let's put it this way: If I have the choice of believing that writeToFile:atomically: doesn't work as advertised, or that a random poster on stack overflow can't get his code right, I'll believe the latter. – gnasher729 Sep 23 '14 at 14:57
  • Fair enough, makes sense. Does that mean that `waitUntilDone:YES` only makes sense if you tell it to run the selector on a thread different than the current thread? In that case, the current thread's execution would block until the other thread has executed the selector, right? – nyi Sep 24 '14 at 07:17