I have a method which should support being called from any queue, and should expect to.
It runs some code in a background thread itself, and then uses dispatch
I have the same functional requirements the original post mentions. You should be able to call this async function on any queue, but if called on the main queue, then callback to the user on the main queue. I simply handle it like so:
// cache value for if we should callback on main queue
BOOL callbackOnMT = [NSThread isMainThread];
// ...
// ... do async work...
// ...
if (callbackOnMT && ![NSThread isMainThread]){
dispatch_async(dispatch_get_main_queue(), ^{
// callback to user on main queue
// as they called this function on main queue
callbackToUser();
});
}
else{
// callback to user on our current queue
// as they called this function on a non-main queue
callbackToUser();
}