Just wanted to let you know I had a couple of additional interesting requirements I would like to build on top of this:
My network operation can either be user-initiated, e.g. from a pull-to-refresh, or background-initated, e.g. from a push notification. I would like to coalesce these but they have different NSOperationqualityOfService levels. I was thinking about trying to promote the QOS of an existing background operation if a subsequent user-initated operation is enqueued.
If a network operation is part-way through then I don't want to coalesce another one, because new data might be available on the server to be downloaded. However if there is a part-way one, and another one, then the 3rd can be coalesced (since the 2nd hasn't even been started so no chance of missing anything).
The operations I'll be coalescing have multiple progress blocks, not just completion.
Also I have a question about your design, why did you choose to the coalescing at the enqueuing of the new operation, rather than at the end of the old operation, e.g. at the last step to look into the queue and cancelling any queued operations that are the same as the one just ending. I thought it might be more thread-safe to do it inside an operation, but I suppose that's only if its a serial queue.
Any feedback on how to handle (or if to not bother about) these 3 requirements would be greatly appreciated! Thanks