I have a facade over an asynchronous network call—that also performs pagination, ie multiple network calls in order to handle very large result sets—along the lines of this but I now want to use it in a context where knowing when it's finished iterating is important (e.g in an NSOperation
):
[enumerateFoosAtURL:URL usingBlock:^(id foo, BOOL *stop) {
...
} failure:^(NSError *error) {
...
}];
The simplest thing might be to add an extra block but that is so sucky I nearly vomited in my mouth just typing out the example below:
[enumerateFoosAtURL:URL usingBlock:^(id foo, BOOL *stop) {
...
} success:^{
// we're done
} failure:^(NSError *error) {
...
}];
A less sucky option might be to indicate if there are more to come:
[enumerateFoosAtURL:URL usingBlock:^(id foo, BOOL more, BOOL *stop) {
...
if (!more) {
// we're done
}
} failure:^(NSError *error) {
...
}];
Yet another option that I think I like the most might be to simply transform the semantics of the original into this:
[enumerateFoosAtURL:URL usingBlock:^(id foo, BOOL *stop) {
...
} finished:^(NSError *error) {
if (error) {
// an error occurred
} else {
// we're done
...
}
}];
Thoughts?