My library exposes 2 APIs as follows to:
-(void) createFile{
dispatch_sync(queueSerial, ^{ //B1
[fileObj createFileInfo:file completion:^(NSError *error){
//execute completion block C1
}];
});
}
-(void) readFile:(NSData*)timeStamp{
dispatch_async(queueSerial, ^{ //B2
[fileObj readFileInfo:fileName completion:^(NSError *error) {
dispatch_async(queueSerial2, ^{
//execute completion block C2
});
}]
});
}
Both readFile
and createFile
are asynchronous methods.
I usually recommend to the people using my library to call createFile
before readFile
. However, there is no guarantee how the callers will end up implementing this. It usually gets invoked in the following fashion (and I have no control over this)
[fileClass createFile];
[fileClass readFile:timeStamp];
What I want to do is to ensure readFile
gets called after the completion block C1
is executed. I also don't want to block the main thread with createFile
(but this expectation can be relaxed). So what I want to achieve as end result is :
- Caller (that I have no control over) calls
createFile
and immediately after callsreadFile
createFile
fully executes, completion blockC1
gets fired and after that,readFile
is dispatched to do it's thing.
How can I achieve this?